From 2e30c4016ba36e4cebe15c33ba0f6fde178f1750 Mon Sep 17 00:00:00 2001 From: Yannis Spiliopoulos Date: Sun, 24 Jul 2016 12:29:17 -0400 Subject: [PATCH] Fix request_force_stop_sigrtmin failing for python3 request_force_stop_sigrtmin would fail for python3 because it would try to read frame attributes that have been removed in python3 This patch fixes that by reading more fram attributes only for python2 --- rq/worker.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/rq/worker.py b/rq/worker.py index 5de6403..f4dec4a 100644 --- a/rq/worker.py +++ b/rq/worker.py @@ -734,8 +734,12 @@ class HerokuWorker(Worker): causes the horse to crash `imminent_shutdown_delay` seconds later """ imminent_shutdown_delay = 6 - frame_properties = ['f_code', 'f_exc_traceback', 'f_exc_type', 'f_exc_value', - 'f_lasti', 'f_lineno', 'f_locals', 'f_restricted', 'f_trace'] + + frame_properties = ['f_code', 'f_lasti', 'f_lineno', 'f_locals', 'f_trace'] + if sys.version_info[:2] <= (3, 0): + frame_properties.extend( + ['f_exc_traceback', 'f_exc_type', 'f_exc_value', 'f_restricted'] + ) def setup_work_horse_signals(self): """Modified to ignore SIGINT and SIGTERM and only handle SIGRTMIN""" @@ -753,10 +757,10 @@ class HerokuWorker(Worker): def request_stop_sigrtmin(self, signum, frame): if self.imminent_shutdown_delay == 0: - logger.warn('Imminent shutdown, raising ShutDownImminentException immediately') + self.log.warning('Imminent shutdown, raising ShutDownImminentException immediately') self.request_force_stop_sigrtmin(signum, frame) else: - logger.warn('Imminent shutdown, raising ShutDownImminentException in %d seconds', + self.log.warning('Imminent shutdown, raising ShutDownImminentException in %d seconds', self.imminent_shutdown_delay) signal.signal(signal.SIGRTMIN, self.request_force_stop_sigrtmin) signal.signal(signal.SIGALRM, self.request_force_stop_sigrtmin) @@ -764,5 +768,5 @@ class HerokuWorker(Worker): def request_force_stop_sigrtmin(self, signum, frame): info = dict((attr, getattr(frame, attr)) for attr in self.frame_properties) - logger.warn('raising ShutDownImminentException to cancel job...') + self.log.warning('raising ShutDownImminentException to cancel job...') raise ShutDownImminentException('shut down imminent (signal: %s)' % signal_name(signum), info)