mirror of
https://github.com/livekit/agents.git
synced 2026-12-06 04:28:34 +00:00
50 lines
1.1 KiB
Python
50 lines
1.1 KiB
Python
from __future__ import annotations
|
|
|
|
import gc
|
|
import json
|
|
import multiprocessing as mp
|
|
import weakref
|
|
from multiprocessing.connection import Connection
|
|
|
|
from livekit.agents.ipc import configure_forkserver
|
|
|
|
|
|
class _Cycle:
|
|
reference: _Cycle
|
|
|
|
|
|
def _inspect_gc(connection: Connection) -> None:
|
|
freeze_count = gc.get_freeze_count()
|
|
|
|
cycle = _Cycle()
|
|
cycle.reference = cycle
|
|
cycle_reference = weakref.ref(cycle)
|
|
del cycle
|
|
gc.collect()
|
|
|
|
connection.send(
|
|
{
|
|
"freeze_count": freeze_count,
|
|
"child_cycle_collected": cycle_reference() is None,
|
|
}
|
|
)
|
|
connection.close()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
context = mp.get_context("forkserver")
|
|
configure_forkserver(context, ())
|
|
parent_connection, child_connection = context.Pipe(duplex=False)
|
|
process = context.Process(target=_inspect_gc, args=(child_connection,))
|
|
|
|
process.start()
|
|
child_connection.close()
|
|
outcome = parent_connection.recv()
|
|
parent_connection.close()
|
|
process.join()
|
|
|
|
if process.exitcode != 0:
|
|
raise SystemExit(process.exitcode)
|
|
|
|
print(json.dumps(outcome))
|