Workaround for os.waitpid() throwing an OSError on SIGINT.

When SIGINT (``Ctrl+C``) is received when inside a blocking
os.waitpid(), OSError is thrown, effectively cancelling the wait.

However, to facilitate a "warm shutdown", as we intend, Ctrl+C is
perfectly allowed and we want to keep waiting for the child.  Therefore,
we perform a trick here, catching OSError, checking whether its cause
was SIGINT (errno == EINTR), and only in that case, loop to os.waitpid()
again.
main
Vincent Driessen 13 years ago
parent e278bd2967
commit 1cbf92c166

@ -244,7 +244,15 @@ class Worker(object):
sys.exit(0) sys.exit(0)
else: else:
self.procline('Forked %d at %d' % (child_pid, time.time())) self.procline('Forked %d at %d' % (child_pid, time.time()))
while True:
try:
os.waitpid(child_pid, 0) os.waitpid(child_pid, 0)
break
except OSError as e:
if e.errno == errno.EINTR:
self.log.info('Not waiting for child.... received SIGINT.')
else:
raise
def perform_job(self, job): def perform_job(self, job):
self.procline('Processing %s from %s since %s' % ( self.procline('Processing %s from %s since %s' % (

Loading…
Cancel
Save