Do not run it on the event loop. Options: a process pool (concurrent.futures.ProcessPoolExecutor with loop.run_in_executor), a task queue with separate workers (Celery, RQ, Arq, Dramatiq) for jobs that need retries and persistence, or a separate service (for example a model-serving system such as Triton or vLLM for inference).
Return a job ID immediately and let the client poll or receive a webhook or a WebSocket notification when the work completes.
Loading…