summaryrefslogtreecommitdiff
path: root/kvmd/aiotools.py
diff options
context:
space:
mode:
Diffstat (limited to 'kvmd/aiotools.py')
-rw-r--r--kvmd/aiotools.py15
1 files changed, 15 insertions, 0 deletions
diff --git a/kvmd/aiotools.py b/kvmd/aiotools.py
index d2c73325..f93669f9 100644
--- a/kvmd/aiotools.py
+++ b/kvmd/aiotools.py
@@ -21,6 +21,7 @@
import asyncio
+import signal
import functools
import types
@@ -102,6 +103,20 @@ async def close_writer(writer: asyncio.StreamWriter) -> bool:
# =====
+def run(coro: Coroutine) -> None:
+ def sigint_handler() -> None:
+ raise KeyboardInterrupt()
+
+ def sigterm_handler() -> None:
+ raise SystemExit()
+
+ loop = asyncio.get_event_loop()
+ loop.add_signal_handler(signal.SIGINT, sigint_handler)
+ loop.add_signal_handler(signal.SIGTERM, sigterm_handler)
+ loop.run_until_complete(coro)
+
+
+# =====
class AioNotifier:
def __init__(self) -> None:
self.__queue: "asyncio.Queue[None]" = asyncio.Queue()