mirror of
https://github.com/mofeng-git/One-KVM.git
synced 2026-01-29 00:51:53 +08:00
signals handling
This commit is contained in:
@@ -21,6 +21,7 @@
|
||||
|
||||
|
||||
import asyncio
|
||||
import signal
|
||||
import functools
|
||||
import types
|
||||
|
||||
@@ -101,6 +102,20 @@ async def close_writer(writer: asyncio.StreamWriter) -> bool:
|
||||
return (not closing)
|
||||
|
||||
|
||||
# =====
|
||||
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:
|
||||
|
||||
Reference in New Issue
Block a user