From 92a25655078a06facf3e6c34217bcd1de1272738 Mon Sep 17 00:00:00 2001 From: David Wilson Date: Wed, 2 May 2018 16:51:50 +0100 Subject: [PATCH] issue #241: child main thread does not gracefully handle CTRL+C In Ansible, depending on when CTRL+C is triggered, if it occurs after the connection multiplexer process has forked, and after it has in turn forked the "connection: local" context and its corresponding "clean fork parent", since all the broker processes still belong to Ansible's terminal foreground process group, they are all capable of receiving SIGINT in response to CTRL+C being pressed on that terminal. This papers over the problem. Really we want those KeyboardInterrupts to be logged, to call setsid() frmo the connection multiplexer process to isolate it from the terminal foreground process group. That way its only indication of top-level process shutdown is using the graceful disconnect mechanism that already exists in process.py::worker_main(). --- mitogen/core.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/mitogen/core.py b/mitogen/core.py index bd4493e9..56fc3266 100644 --- a/mitogen/core.py +++ b/mitogen/core.py @@ -1684,6 +1684,8 @@ class ExternalContext(object): _profile_hook('main', self._dispatch_calls) _v and LOG.debug('ExternalContext.main() normal exit') + except KeyboardInterrupt: + LOG.debug('KeyboardInterrupt received, exiting gracefully.') except BaseException: LOG.exception('ExternalContext.main() crashed') raise