From bdc76c8231433de7193f70be7f27867fba329a41 Mon Sep 17 00:00:00 2001 From: David Wilson Date: Wed, 18 Apr 2018 16:43:27 +0100 Subject: [PATCH] parent: do not attempt to reap child twice. --- mitogen/parent.py | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/mitogen/parent.py b/mitogen/parent.py index 03373bbc..95cbbc14 100644 --- a/mitogen/parent.py +++ b/mitogen/parent.py @@ -483,14 +483,29 @@ class Stream(mitogen.core.Stream): ) ) - def on_disconnect(self, broker): + _reaped = False + + def _reap_child(self): + """ + Reap the child process during disconnection. + """ + if self._reaped: + # on_disconnect() may be invoked more than once, for example, if + # there is still a pending message to be sent after the first + # on_disconnect() call. + return + pid, status = os.waitpid(self.pid, os.WNOHANG) if pid: LOG.debug('%r: child process exit status was %d', self, status) else: LOG.debug('%r: child process still alive, sending SIGTERM', self) os.kill(self.pid, signal.SIGTERM) - pid, status = os.waitpid(self.pid, 0) + os.waitpid(self.pid, 0) + self._reaped = True + + def on_disconnect(self, broker): + self._reap_child() super(Stream, self).on_disconnect(broker) # Minimised, gzipped, base64'd and passed to 'python -c'. It forks, dups