summaryrefslogtreecommitdiff
path: root/kvmd
diff options
context:
space:
mode:
authorDevaev Maxim <[email protected]>2020-03-04 04:18:35 +0300
committerDevaev Maxim <[email protected]>2020-03-04 04:18:35 +0300
commit779a9f1d1527edd89bc9d72a9b9d4cb0cbbef457 (patch)
tree164f3219a98b06a6fa01d964d78a38d91daa09a1 /kvmd
parent52e117df3c1fbfc29524ca9d06e49605b3ec5992 (diff)
receiving ustreamer signals
Diffstat (limited to 'kvmd')
-rw-r--r--kvmd/apps/kvmd/streamer.py16
1 files changed, 15 insertions, 1 deletions
diff --git a/kvmd/apps/kvmd/streamer.py b/kvmd/apps/kvmd/streamer.py
index 999033a7..ba2e4c53 100644
--- a/kvmd/apps/kvmd/streamer.py
+++ b/kvmd/apps/kvmd/streamer.py
@@ -29,6 +29,7 @@ from typing import List
from typing import Dict
from typing import AsyncGenerator
from typing import Optional
+from typing import Any
import aiohttp
@@ -197,13 +198,26 @@ class Streamer: # pylint: disable=too-many-instance-attributes
}
async def poll_state(self) -> AsyncGenerator[Dict, None]:
+ notifier = aiotools.AioNotifier()
+
+ def signal_handler(*_: Any) -> None:
+ get_logger(0).info("Got SIGUSR2, checking the stream state ...")
+ asyncio.ensure_future(notifier.notify())
+
+ get_logger(0).info("Installing SIGUSR2 streamer handler ...")
+ asyncio.get_event_loop().add_signal_handler(signal.SIGUSR2, signal_handler)
+
prev_state: Dict = {}
while True:
state = await self.get_state()
if state != prev_state:
yield state
prev_state = state
- await asyncio.sleep(self.__state_poll)
+
+ await asyncio.wait([
+ asyncio.sleep(self.__state_poll),
+ notifier.wait(),
+ ], return_when=asyncio.FIRST_COMPLETED)
async def get_info(self) -> Dict:
proc = await asyncio.create_subprocess_exec(