Skip to content

Instantly share code, notes, and snippets.

@schipiga
Last active December 6, 2019 16:49
Show Gist options
  • Save schipiga/223091e5115f3cbee09fa5fc0b54dd87 to your computer and use it in GitHub Desktop.
Save schipiga/223091e5115f3cbee09fa5fc0b54dd87 to your computer and use it in GitHub Desktop.
class PoolManager: # already existing class
def start(self):
self.init_signals() # added by me
self.worker_manager.create_workers()
# all below added by me
def init_signals(self):
if hasattr(signal, 'SIGCHLD'):
signal.signal(signal.SIGCHLD, handle_chld)
def handle_chld(signum, frame):
reap_workers()
def reap_workers():
try:
while True:
wpid, status = os.waitpid(-1, os.WNOHANG)
if not wpid:
break
except OSError as e:
if e.errno != errno.ECHILD:
raise e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment