Browse Source

Add SIGQUIT handler that terminates the pool, and unit test

Alec Clowes 13 years ago
parent
commit
7c2b38557a
2 changed files with 22 additions and 0 deletions
  1. 13 0
      celery/apps/worker.py
  2. 9 0
      celery/tests/test_bin/test_celeryd.py

+ 13 - 0
celery/apps/worker.py

@@ -245,6 +245,7 @@ class Worker(configurated):
             else:
                 install_worker_restart_handler(worker)
         install_worker_term_handler(worker)
+        install_worker_term_hard_handler(worker)
         install_worker_int_handler(worker)
         install_cry_handler(worker.logger)
         install_rdb_handler()
@@ -346,3 +347,15 @@ def install_HUP_not_supported_handler(worker):
             "Restarting with HUP is unstable on this platform!")
 
     platforms.signals["SIGHUP"] = warn_on_HUP_handler
+
+
+def install_worker_term_hard_handler(worker):
+
+    def _stop(signum, frame):
+        process_name = get_process_name()
+        if not process_name or process_name == "MainProcess":
+            worker.logger.warning("celeryd: Cold shutdown (%s)" % (process_name, ))
+            worker.terminate(in_sighandler=True)
+        raise SystemExit()
+
+    platforms.signals["SIGQUIT"] = _stop

+ 9 - 0
celery/tests/test_bin/test_celeryd.py

@@ -567,3 +567,12 @@ class test_signal_handlers(AppCase):
             self.assertTrue(argv)
         finally:
             os.execv = execv
+
+
+    @disable_stdouts
+    def test_worker_term_hard_handler(self):
+        worker = self._Worker()
+        handlers = self.psig(cd.install_worker_term_hard_handler, worker)
+        with self.assertRaises(SystemExit):
+            handlers["SIGQUIT"]("SIGQUIT", object())
+        self.assertTrue(worker.terminated)