kind-family-60542
09/15/2025, 6:12 PMmain.py and share these objects with any class that needs to connect to a database/redis cache/grpc service/etc. There is a single client for the entire time that the service is up.
The problem with LiveKit workers is that they create a new asyncio event loop for every entrypoint inside _ProcClient.run (please correct me if I'm wrong), and calls to, e.g., the async Redis client, will fail because that singleton client was created in a different loop.
One way to fix it is to create a new client on every session received in the entrypoint function, creating a new connection pool or asyncio channel, etc. Another option we found is to set up LiveKit to spawn threads instead of processes (by using opts.job_executor_type = JobExecutorType.THREAD) and create a threading.local() variable to initialize a new Redis client but for each thread. If LiveKit uses a thread pool, it should reuse these clients instead of creating new instances on every call request. But this approach still affects the startup time of the entrypoint function.
How feasible is it to share an event loop between worker processes to avoid these issues?kind-family-60542
09/15/2025, 6:18 PMrefined-appointment-81829
09/15/2025, 8:33 PMkind-family-60542
09/15/2025, 10:35 PM