mirror of
https://github.com/mofeng-git/One-KVM.git
synced 2025-12-12 01:00:29 +08:00
refactoring
This commit is contained in:
parent
607e5a9877
commit
93e28c62e5
@ -67,18 +67,13 @@ class Server: # pylint: disable=too-many-instance-attributes
|
|||||||
app.on_cleanup.append(self.__on_cleanup)
|
app.on_cleanup.append(self.__on_cleanup)
|
||||||
|
|
||||||
self.__system_tasks.extend([
|
self.__system_tasks.extend([
|
||||||
self.__loop.create_task(self.__monitor_keyboard()),
|
self.__loop.create_task(self.__keyboard_watchdog()),
|
||||||
self.__loop.create_task(self.__stream_controller()),
|
self.__loop.create_task(self.__stream_controller()),
|
||||||
self.__loop.create_task(self.__poll_dead_sockets()),
|
self.__loop.create_task(self.__poll_dead_sockets()),
|
||||||
self.__loop.create_task(self.__poll_atx_leds()),
|
self.__loop.create_task(self.__poll_atx_leds()),
|
||||||
])
|
])
|
||||||
|
|
||||||
aiohttp.web.run_app(
|
aiohttp.web.run_app(app, host=host, port=port, print=self.__run_app_print)
|
||||||
app=app,
|
|
||||||
host=host,
|
|
||||||
port=port,
|
|
||||||
print=(lambda text: [get_logger().info(line.strip()) for line in text.strip().splitlines()]), # type: ignore
|
|
||||||
)
|
|
||||||
|
|
||||||
async def __root_handler(self, _: aiohttp.web.Request) -> aiohttp.web.Response:
|
async def __root_handler(self, _: aiohttp.web.Request) -> aiohttp.web.Response:
|
||||||
return aiohttp.web.Response(text="OK")
|
return aiohttp.web.Response(text="OK")
|
||||||
@ -96,6 +91,11 @@ class Server: # pylint: disable=too-many-instance-attributes
|
|||||||
break
|
break
|
||||||
return ws
|
return ws
|
||||||
|
|
||||||
|
def __run_app_print(self, text: str) -> None:
|
||||||
|
logger = get_logger()
|
||||||
|
for line in text.strip().splitlines():
|
||||||
|
logger.info(line.strip())
|
||||||
|
|
||||||
async def __on_shutdown(self, _: aiohttp.web.Application) -> None:
|
async def __on_shutdown(self, _: aiohttp.web.Application) -> None:
|
||||||
logger = get_logger(0)
|
logger = get_logger(0)
|
||||||
|
|
||||||
@ -115,7 +115,7 @@ class Server: # pylint: disable=too-many-instance-attributes
|
|||||||
await self.__streamer.stop()
|
await self.__streamer.stop()
|
||||||
|
|
||||||
@_system_task
|
@_system_task
|
||||||
async def __monitor_keyboard(self) -> None:
|
async def __keyboard_watchdog(self) -> None:
|
||||||
while self.__keyboard.is_alive():
|
while self.__keyboard.is_alive():
|
||||||
await asyncio.sleep(0.1)
|
await asyncio.sleep(0.1)
|
||||||
raise RuntimeError("Keyboard dead")
|
raise RuntimeError("Keyboard dead")
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user