Browse Source

Close context on restart if detached

Ask Solem 15 years ago
parent
commit
4b7c831957
1 changed files with 4 additions and 3 deletions
  1. 4 3
      celery/bin/celeryd.py

+ 4 - 3
celery/bin/celeryd.py

@@ -263,7 +263,7 @@ def run_worker(concurrency=DAEMON_CONCURRENCY, detach=False,
                                 is_detached=detach)
 
         # Install signal handler that restarts celeryd on SIGHUP
-        install_restart_signal_handler(worker)
+        install_restart_signal_handler(worker, context)
 
         try:
             worker.start()
@@ -282,7 +282,7 @@ def run_worker(concurrency=DAEMON_CONCURRENCY, detach=False,
         raise
 
 
-def install_restart_signal_handler(worker):
+def install_restart_signal_handler(worker, context):
     """Installs a signal handler that restarts the current program
     when it receives the ``SIGHUP`` signal.
     """
@@ -295,10 +295,11 @@ def install_restart_signal_handler(worker):
             pid = os.fork()
             if pid:
                 worker.stop()
+                context.close()
                 sys.exit(0)
         else:
             worker.stop()
-        os.execve(sys.executable, [sys.executable] + sys.argv, os.environ)
+        os.execv(sys.executable, [sys.executable] + sys.argv)
 
     signal(SIGHUP, restart_self)