diff options
Diffstat (limited to 'packages/meshbay-node/src/meshbay_node/daemon.py')
| -rw-r--r-- | packages/meshbay-node/src/meshbay_node/daemon.py | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/packages/meshbay-node/src/meshbay_node/daemon.py b/packages/meshbay-node/src/meshbay_node/daemon.py index b932c16..ea13680 100644 --- a/packages/meshbay-node/src/meshbay_node/daemon.py +++ b/packages/meshbay-node/src/meshbay_node/daemon.py @@ -678,9 +678,18 @@ class NodeDaemon: # 12. Wait for shutdown stop_event = asyncio.Event() loop = asyncio.get_event_loop() + console_shutdown_done = None if sys.platform == "win32": - for sig in (signal.SIGINT, signal.SIGTERM): + # SIGBREAK: CTRL_BREAK_EVENT, how platform.autostart_end() asks + # a per-user-mode daemon to stop gracefully instead of only + # ever taskkill /F. + for sig in (signal.SIGINT, signal.SIGTERM, signal.SIGBREAK): signal.signal(sig, lambda *_: stop_event.set()) + # CTRL_CLOSE/LOGOFF/SHUTDOWN reach no Python signal at all -- + # see platform.install_console_close_handler for why this is + # a separate mechanism rather than another signal.signal() line. + from meshbay_node.platform import install_console_close_handler + console_shutdown_done = install_console_close_handler(loop, stop_event) else: for sig in (signal.SIGINT, signal.SIGTERM): loop.add_signal_handler(sig, stop_event.set) @@ -694,6 +703,13 @@ class NodeDaemon: await stop_event.wait() await self._shutdown() + if console_shutdown_done is not None: + # Releases the console-control handler's blocking wait (see + # platform.install_console_close_handler) so it can return and + # let Windows actually end the process for CTRL_CLOSE/LOGOFF/ + # SHUTDOWN, now that cleanup is genuinely done rather than just + # started. + console_shutdown_done.set() async def _reload_config(self) -> None: """ |