From 320fe3358401eb6d8a717ef63c5d4a50d89d20bb Mon Sep 17 00:00:00 2001 From: ojhdt Date: Sun, 1 Jan 2023 00:34:17 +0800 Subject: [PATCH] loop stoppable --- efb_parabox_master/server.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/efb_parabox_master/server.py b/efb_parabox_master/server.py index 73b20de..21d2721 100644 --- a/efb_parabox_master/server.py +++ b/efb_parabox_master/server.py @@ -47,6 +47,7 @@ def __init__(self, channel: 'ParaboxChannel'): self.websocket_users = set() # run self.run_main in another thread + self.loop = asyncio.new_event_loop() self.thread = threading.Thread(target=self.run_main) self.thread.start() @@ -55,6 +56,7 @@ def pulling(self): def graceful_stop(self): self.logger.debug("Websocket server stopped") + self.loop.stop() async def msg_looper(self): while True: @@ -102,10 +104,9 @@ def send_status(self, status: 'Status'): def run_server(self): self.logger.info("Websocket listening at %s : %s", self.host, self.port) - loop = asyncio.new_event_loop() # asyncio.set_event_loop(loop) # server = websockets.serve(self.handler, self.host, self.port) - asyncio.run_coroutine_threadsafe(self.server_main(), loop) + asyncio.run_coroutine_threadsafe(self.server_main(), self.loop) # asyncio.run(self.server_main()) async def server_main(self):