From 14f7fe9e314930c86a9325c32e906112bbf7f03c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elan=20Ruusam=C3=A4e?= Date: Sun, 29 Dec 2024 14:49:38 +0200 Subject: [PATCH] Add asyncio shutdown to cli KeyboardInterrupt --- plextraktsync/cli.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/plextraktsync/cli.py b/plextraktsync/cli.py index 36bc630654..aec5582e17 100644 --- a/plextraktsync/cli.py +++ b/plextraktsync/cli.py @@ -28,6 +28,22 @@ def wrap(*args, **kwargs): cmd(*args, **kwargs) except EOFError as e: raise ClickException(f"Program requested terminal, No terminal is connected: {e}") + except KeyboardInterrupt: + # from plextraktsync.factory import logging + # logger = logging.getLogger(__name__) + # logger.error(e) + # + import asyncio + + try: + loop = asyncio.get_event_loop() + loop.stop() + loop.close() + except RuntimeError: + pass + + # raise ClickException(f"Interrupted! [{e}]") from None + raise ClickException("Interrupted!") except ClickException as e: from plextraktsync.factory import logging