From f3c24db18de2cf3572c5ce17cf30dcb1ac4f5958 Mon Sep 17 00:00:00 2001 From: Will McGugan Date: Tue, 22 Aug 2023 16:20:53 +0100 Subject: [PATCH] don't add signal handler on Windows --- src/textual/drivers/web_driver.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/textual/drivers/web_driver.py b/src/textual/drivers/web_driver.py index e9adb1a923..8920182db8 100644 --- a/src/textual/drivers/web_driver.py +++ b/src/textual/drivers/web_driver.py @@ -14,6 +14,7 @@ import asyncio import json import os +import platform import selectors import signal import sys @@ -28,6 +29,8 @@ from ..geometry import Size from ._byte_stream import ByteStream +WINDOWS = platform.system() == "Windows" + class WebDriver(Driver): """A headless driver that may be run remotely.""" @@ -95,8 +98,9 @@ def do_exit() -> None: self._app._post_message(messages.ExitApp()), loop=loop ) - for _signal in (signal.SIGINT, signal.SIGTERM): - loop.add_signal_handler(_signal, do_exit) + if not WINDOWS: + for _signal in (signal.SIGINT, signal.SIGTERM): + loop.add_signal_handler(_signal, do_exit) self._write(b"__GANGLION__\n") @@ -185,3 +189,7 @@ def on_meta(self, packet_type: str, payload: dict) -> None: self._app._post_message(event), loop=self._loop, ) + elif packet_type == "quit": + asyncio.run_coroutine_threadsafe( + self._app._post_message(messages.ExitApp()), loop=self._loop + )