Browse Source

[Prefork] Reset celery.worker.state after fork

Ask Solem 9 years ago
parent
commit
8ef663e8b3
2 changed files with 10 additions and 0 deletions
  1. 2 0
      celery/concurrency/prefork.py
  2. 8 0
      celery/worker/state.py

+ 2 - 0
celery/concurrency/prefork.py

@@ -81,6 +81,8 @@ def process_initializer(app, hostname):
     for name, task in items(app.tasks):
         task.__trace__ = build_tracer(name, task, app.loader, hostname,
                                       app=app)
+    from celery.worker import state as worker_state
+    worker_state.reset_state()
     signals.worker_process_init.send(sender=None)
 
 

+ 8 - 0
celery/worker/state.py

@@ -63,6 +63,14 @@ should_stop = None
 should_terminate = None
 
 
+def reset_state():
+    reserved_requests.clear()
+    active_requests.clear()
+    total_count.clear()
+    all_total_count[:] = [0]
+    revoked.clear()
+
+
 def maybe_shutdown():
     if should_stop is not None and should_stop is not False:
         raise WorkerShutdown(should_stop)