Skip to content

Commit

Permalink
Ensure that SIGHUP followed by SIGINT, the SIGINT is respected.
Browse files Browse the repository at this point in the history
Refs #755
  • Loading branch information
coleifer committed Apr 4, 2024
1 parent 054165e commit 2e3f08b
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion huey/consumer.py
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,7 @@ def stop(self, graceful=False):
self.scheduler.join()
except KeyboardInterrupt:
self._logger.info('Received request to shut down now.')
self._restart = False
else:
self._logger.info('All workers have stopped.')
else:
Expand Down Expand Up @@ -510,12 +511,14 @@ def check_worker_health(self):

def _set_signal_handlers(self):
signal.signal(signal.SIGTERM, self._handle_stop_signal)
if self.worker_type == WORKER_GREENLET:
if self.worker_type in (WORKER_GREENLET, WORKER_THREAD):
# Add a special INT handler when using gevent. If the running
# greenlet is not the main hub, then Gevent will raise a
# KeyboardInterrupt in the running greenlet by default. This
# ensures that when INT is received we properly flag the main loop
# for graceful shutdown and do NOT propagate the exception.
# This is also added for threads to ensure that, in the event of a
# SIGHUP followed by a SIGINT, we respect the SIGINT.
signal.signal(signal.SIGINT, self._handle_interrupt_signal_gevent)
else:
signal.signal(signal.SIGINT, signal.default_int_handler)
Expand Down

0 comments on commit 2e3f08b

Please sign in to comment.