Python & FastAPI•Part 5: ORMs, Databases & Background Workers (56 - 65)
Preventing Worker Memory Leaks:
In Simple Words:
Python workers running heavy libraries can suffer from fragmented RAM over time. Configure max_tasks_per_child to restart worker processes periodically.
python
# Celery worker configuration:
celery_app.conf.update(
worker_max_tasks_per_child=1000, # Restart worker after 1000 tasks
worker_max_memory_per_child=200000 # 200MB limit
)