Skip to content

Commit

Permalink
Add SIGQUIT handler that terminates the pool, and unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
aclowes committed Feb 14, 2012
1 parent e810420 commit 7c2b385
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
13 changes: 13 additions & 0 deletions celery/apps/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ def install_platform_tweaks(self, worker):
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()
Expand Down Expand Up @@ -346,3 +347,15 @@ def warn_on_HUP_handler(signum, frame):
"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 changes: 9 additions & 0 deletions celery/tests/test_bin/test_celeryd.py
Original file line number Diff line number Diff line change
Expand Up @@ -567,3 +567,12 @@ def _execv(*args):
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)

0 comments on commit 7c2b385

Please sign in to comment.