some-breakfast-27057
09/29/2025, 10:54 AMtall-airline-16756
09/29/2025, 10:54 AMtall-airline-16756
09/29/2025, 10:56 AMmultiprocessing_context parameter in the WorkerOptions class to use the "spawn" context instead of the default "forkserver" on Linux. This simple change helps avoid creating multiple forkserver processes:
from livekit.agents import WorkerOptions
opts = WorkerOptions(
entrypoint_fnc=your_entrypoint_function,
multiprocessing_context="spawn" # Prevents forkserver usage
)
To make sure only one Python process runs even when there’s high load or multiple sessions, here are a couple of helpful tips:
• Set num_idle_processes = 1 to limit the number of pre-warmed processes.
• Use a custom load_fnc that returns 1.0 whenever any job is active, so the worker is marked as unavailable for new jobs.
Here’s an example configuration to guide you:
async def entrypoint(ctx: JobContext):
await ctx.connect()
await ctx.shutdown()
def custom_load(worker):
return 1.0 if len(worker.active_jobs) > 0 else 0.0
worker = Worker(
opts=WorkerOptions(
entrypoint_fnc=entrypoint,
load_fnc=custom_load,
load_threshold=0.7,
num_idle_processes=1,
)
)
This setup helps ensure that only one process runs at a time. If you have any questions or need a hand with anything else, please feel free to ask—I’m here to help!
Sources: tests/test_ipc.py | Deploying to custom environments | LiveKit Docs | Docs::Agents | Worker options | LiveKit Docs | Inside a session | LiveKit Docssome-breakfast-27057
09/29/2025, 11:52 AMtall-airline-16756
09/29/2025, 11:53 AM