From d2604c63dfd4730417c8613efaa52d97044702c2 Mon Sep 17 00:00:00 2001 From: Remy Tuyeras Date: Wed, 18 Feb 2026 12:00:02 -0500 Subject: [PATCH] fix shutdown with ctrl+C --- summoner/client/client.py | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/summoner/client/client.py b/summoner/client/client.py index b91f92a..01707ab 100644 --- a/summoner/client/client.py +++ b/summoner/client/client.py @@ -1436,8 +1436,8 @@ async def handle_session(self, host: str = '127.0.0.1', port: int = 8888): # Deregister this session and its children from active tasks async with self.tasks_lock: - if task is not None: - self.active_tasks.discard(task) + if current_task is not None: + self.active_tasks.discard(current_task) # Check whether we should quit or loop back to travel to the next server (agent migration) async with self.connection_lock: @@ -1459,7 +1459,21 @@ def set_termination_signals(self): """ if platform.system() != "Windows": for sig in (signal.SIGINT, signal.SIGTERM): - self.loop.add_signal_handler(sig, lambda: self.shutdown()) + self.loop.add_signal_handler(sig, self.shutdown) + else: + def _handler(sig, frame): + # thread-safe: schedule shutdown on the event loop + try: + self.loop.call_soon_threadsafe(self.shutdown) + except RuntimeError: + pass + signal.signal(signal.SIGINT, _handler) + # SIGTERM exists on Windows in Python, but behavior varies by launcher + if hasattr(signal, "SIGTERM"): + try: + signal.signal(signal.SIGTERM, _handler) + except Exception: + pass async def _wait_for_registration(self): """