From 10af266678f16e7404e025b727934a975b664863 Mon Sep 17 00:00:00 2001 From: David Wilson Date: Sat, 3 Nov 2018 20:54:05 +0000 Subject: [PATCH] issue #406: attempt Broker cleanup in case of a crash. --- mitogen/core.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/mitogen/core.py b/mitogen/core.py index df4e54eb..5b1d5298 100644 --- a/mitogen/core.py +++ b/mitogen/core.py @@ -2473,6 +2473,13 @@ class Broker(object): for (side, func) in self.poller.poll(timeout): self._call(side.stream, func) + def _broker_exit(self): + for _, (side, _) in self.poller.readers + self.poller.writers: + LOG.error('_broker_main() force disconnecting %r', side) + side.stream.on_disconnect(self) + + self.poller.close() + def _broker_shutdown(self): for _, (side, _) in self.poller.readers + self.poller.writers: self._call(side.stream, side.stream.on_shutdown) @@ -2487,12 +2494,6 @@ class Broker(object): 'more child processes still connected to ' 'our stdout/stderr pipes.', self) - for _, (side, _) in self.poller.readers + self.poller.writers: - LOG.error('_broker_main() force disconnecting %r', side) - side.stream.on_disconnect(self) - - self.poller.close() - def _broker_main(self): """ Handle events until :meth:`shutdown`. On shutdown, invoke @@ -2509,6 +2510,7 @@ class Broker(object): except Exception: LOG.exception('_broker_main() crashed') + self._broker_exit() fire(self, 'exit') def shutdown(self):