parent: do not attempt to reap child twice.

pull/192/head
David Wilson 7 years ago
parent 1e882a72c0
commit bdc76c8231

@ -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

Loading…
Cancel
Save