simplified AioNotifier()

This commit is contained in:
Maxim Devaev
2022-08-07 19:04:32 +03:00
parent aa630988cc
commit ec9785b4be
18 changed files with 43 additions and 54 deletions

View File

@@ -213,13 +213,13 @@ class KvmdServer(HttpServer): # pylint: disable=too-many-arguments,too-many-ins
value = validator(value) # type: ignore
if current_params[name] != value:
self.__new_streamer_params[name] = value
await self.__streamer_notifier.notify()
self.__streamer_notifier.notify()
return make_json_response()
@exposed_http("POST", "/streamer/reset")
async def __streamer_reset_handler(self, _: Request) -> Response:
self.__reset_streamer = True
await self.__streamer_notifier.notify()
self.__streamer_notifier.notify()
return make_json_response()
# ===== WEBSOCKET
@@ -299,11 +299,11 @@ class KvmdServer(HttpServer): # pylint: disable=too-many-arguments,too-many-ins
logger.info("On-Cleanup complete")
async def _on_ws_opened(self) -> None:
await self.__streamer_notifier.notify()
self.__streamer_notifier.notify()
async def _on_ws_closed(self) -> None:
self.__hid.clear_events()
await self.__streamer_notifier.notify()
self.__streamer_notifier.notify()
def __has_stream_clients(self) -> bool:
return bool(sum(map(

View File

@@ -96,7 +96,7 @@ class Snapshoter: # pylint: disable=too-many-instance-attributes
logger.info("Time to take the new idle snapshot")
try:
self.__snapshoting = True
await notifier.notify()
notifier.notify()
if not live:
await self.__wakeup()
@@ -116,7 +116,7 @@ class Snapshoter: # pylint: disable=too-many-instance-attributes
logger.exception("Unhandled exception while taking snapshot")
finally:
self.__snapshoting = False
await asyncio.shield(notifier.notify())
notifier.notify()
async def __wakeup(self) -> None:
logger = get_logger(0)

View File

@@ -319,7 +319,7 @@ class Streamer: # pylint: disable=too-many-instance-attributes
async def poll_state(self) -> AsyncGenerator[Dict, None]:
def signal_handler(*_: Any) -> None:
get_logger(0).info("Got SIGUSR2, checking the stream state ...")
asyncio.ensure_future(self.__notifier.notify())
self.__notifier.notify()
get_logger(0).info("Installing SIGUSR2 streamer handler ...")
asyncio.get_event_loop().add_signal_handler(signal.SIGUSR2, signal_handler)
@@ -370,7 +370,7 @@ class Streamer: # pylint: disable=too-many-instance-attributes
)
if save:
self.__snapshot = snapshot
await self.__notifier.notify()
self.__notifier.notify()
return snapshot
logger.error("Stream is offline, no signal or so")
except (aiohttp.ClientConnectionError, aiohttp.ServerConnectionError) as err:

View File

@@ -96,10 +96,10 @@ class PstServer(HttpServer): # pylint: disable=too-many-arguments,too-many-inst
logger.info("On-Cleanup complete")
async def _on_ws_opened(self) -> None:
await self.__notifier.notify()
self.__notifier.notify()
async def _on_ws_closed(self) -> None:
await self.__notifier.notify()
self.__notifier.notify()
# ===== SYSTEM TASKS

View File

@@ -294,7 +294,7 @@ class _Client(RfbClient): # pylint: disable=too-many-instance-attributes
if len(last["data"]) == 0:
# Вдруг какой-то баг
await self.__fb_notifier.notify()
self.__fb_notifier.notify()
continue
if last["format"] == StreamFormats.JPEG:
@@ -305,7 +305,7 @@ class _Client(RfbClient): # pylint: disable=too-many-instance-attributes
if has_h264_key:
await self._send_fb_h264(last["data"])
else:
await self.__fb_notifier.notify()
self.__fb_notifier.notify()
else:
raise RuntimeError(f"Unknown format: {last['format']}")
last["data"] = b""
@@ -406,7 +406,7 @@ class _Client(RfbClient): # pylint: disable=too-many-instance-attributes
await self.__kvmd_session.streamer.set_params(quality, self.__desired_fps)
async def _on_fb_update_request(self) -> None:
await self.__fb_notifier.notify()
self.__fb_notifier.notify()
# =====