From 9cb1bf22978af3248edc02ab88e075c4b91b1571 Mon Sep 17 00:00:00 2001 From: Evan Blaudy Date: Thu, 14 Nov 2024 12:22:18 +0100 Subject: [PATCH] [events][windows] add signal handler on windows platform to properly shutdown the event loop --- gazu/events.py | 18 ++++++++++++++++++ setup.cfg | 1 + 2 files changed, 19 insertions(+) diff --git a/gazu/events.py b/gazu/events.py index 342a3de3..9223fb02 100644 --- a/gazu/events.py +++ b/gazu/events.py @@ -7,7 +7,25 @@ from .exception import AuthFailedException from .client import default_client, get_event_host from gazu.client import make_auth_header +from engineio.base_client import signal_handler import socketio +import os +import inspect +import signal +import socketio + +if os.name == "nt": + from win32api import SetConsoleCtrlHandler + + def WindowsSignalHandler(event): + if event == 0: + try: + signal_handler(signal.SIGINT, inspect.currentframe()) + except: + # SetConsoleCtrlHandler handle cannot raise exceptions + pass + + SetConsoleCtrlHandler(WindowsSignalHandler, 1) class EventsNamespace(socketio.ClientNamespace): diff --git a/setup.cfg b/setup.cfg index a2723b02..78c68eb5 100644 --- a/setup.cfg +++ b/setup.cfg @@ -33,6 +33,7 @@ install_requires = python-socketio[client]>=5.11.0,<6; python_version != '2.7' requests>=2.25.1 Deprecated==1.2.14 + pywin32>=308; sys_platform == 'win32' and python_version != '2.7' [options.packages.find] # ignore gazutest directory