From 4759c43067dfa8daf446d1ae20d39f23a730d9f1 Mon Sep 17 00:00:00 2001 From: Selwin Ong Date: Sun, 23 Sep 2018 20:40:09 +0700 Subject: [PATCH] horse should always call os._exit(0) --- .gitignore | 2 ++ rq/worker.py | 20 +++++++++----------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/.gitignore b/.gitignore index 9cccbd95..ab695b66 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,5 @@ Vagrantfile .idea/ .coverage* /.cache + +.pytest_cache/ diff --git a/rq/worker.py b/rq/worker.py index 9191d7aa..13407e35 100644 --- a/rq/worker.py +++ b/rq/worker.py @@ -463,7 +463,6 @@ class Worker(object): """ setup_loghandlers(logging_level, date_format, log_format) self._install_signal_handlers() - did_perform_work = False self.register_birth() self.log.info("RQ worker {0!r} started, version {1}".format(self.key, VERSION)) @@ -671,16 +670,15 @@ class Worker(object): # that are different from the worker. random.seed() - self.setup_work_horse_signals() - - self._is_horse = True - self.log = logger - - success = self.perform_job(job, queue) - - # os._exit() is the way to exit from childs after a fork(), in - # constrast to the regular sys.exit() - os._exit(0) + try: + self.setup_work_horse_signals() + self._is_horse = True + self.log = logger + self.perform_job(job, queue) + finally: + # os._exit() is the way to exit from childs after a fork(), in + # constrast to the regular sys.exit() + os._exit(0) def setup_work_horse_signals(self): """Setup signal handing for the newly spawned work horse."""