Skip to content

Commit

Permalink
loop stoppable
Browse files Browse the repository at this point in the history
  • Loading branch information
ojhdt committed Dec 31, 2022
1 parent a72a421 commit 320fe33
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions efb_parabox_master/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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:
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit 320fe33

Please sign in to comment.