summaryrefslogtreecommitdiff
path: root/kvmd/aiotools.py
diff options
context:
space:
mode:
authorDevaev Maxim <[email protected]>2021-05-25 23:26:13 +0300
committerDevaev Maxim <[email protected]>2021-05-25 23:26:13 +0300
commit6ce07208a1b6a9fec07d610ced5a73630176662f (patch)
tree6bb7232f3569c3940cec9ad2ffd13544aa365eb0 /kvmd/aiotools.py
parent98c3956994669f9e2a346bdcea9272a351589c96 (diff)
signals handling
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()