EventHorizon-Backend / app /services /executor_service.py
GitHub Actions
Sync backend to Hugging Face (Excluding Audio)
8b0f105
Raw
History Blame Contribute Delete
587 Bytes
import concurrent.futures
_executor = None
def get_executor() -> concurrent.futures.ProcessPoolExecutor:
"""Lazily initialize and return a shared ProcessPoolExecutor."""
global _executor
if _executor is None:
# Use 2 workers to avoid CPU/RAM overhead on lightweight instances
_executor = concurrent.futures.ProcessPoolExecutor(max_workers=2)
return _executor
def shutdown_executor():
"""Shut down the ProcessPoolExecutor cleanly."""
global _executor
if _executor is not None:
_executor.shutdown(wait=False)
_executor = None