Merge pull request #800 from samuelcolvin/heroku-fix

correct heroku worker exit logic
main
Selwin Ong 8 years ago committed by GitHub
commit 21c1e04593

@ -358,12 +358,12 @@ class Worker(object):
signal.signal(signal.SIGINT, self.request_stop)
signal.signal(signal.SIGTERM, self.request_stop)
def kill_horse(self):
def kill_horse(self, sig=signal.SIGKILL):
"""
Kill the horse but catch "No such process" error has the horse could already be dead.
"""
try:
os.kill(self.horse_pid, signal.SIGKILL)
os.kill(self.horse_pid, sig)
except OSError as e:
if e.errno == errno.ESRCH:
# "No such process" is fine with us
@ -838,7 +838,7 @@ class HerokuWorker(Worker):
"""If horse is alive send it SIGRTMIN"""
if self.horse_pid != 0:
self.log.warning('Warm shut down requested, sending horse SIGRTMIN signal')
self.kill_horse()
self.kill_horse(sig=signal.SIGRTMIN)
else:
self.log.warning('Warm shut down requested, no horse found')

@ -884,7 +884,7 @@ class HerokuWorkerShutdownTestCase(TimeoutTestCase, RQTestCase):
w._horse_pid = p.pid
w.handle_warm_shutdown_request()
p.join(2)
self.assertEqual(p.exitcode, -9)
self.assertEqual(p.exitcode, -34)
self.assertFalse(os.path.exists(path))
def test_handle_shutdown_request_no_horse(self):

Loading…
Cancel
Save