diff --git a/example.py b/example.py index b244b60..8ca4d7a 100644 --- a/example.py +++ b/example.py @@ -92,5 +92,9 @@ async def serve(req): #~ logging.basicConfig(format='[%(levelname)-5s] %(name)s: %(message)s',level=logging.DEBUG) #~ logging.getLogger("redys.servone").setLevel( logging.INFO ) + # or with gunicorn : + #> gunicorn -w 4 -k uvicorn.workers.UvicornWorker -b localhost:8000 example:app + # or with uvicorn : + #> uvicorn example:app --workers 4 app.run(openBrowser=True) diff --git a/htagweb/appserver.py b/htagweb/appserver.py index 64e8ea7..cc7e048 100644 --- a/htagweb/appserver.py +++ b/htagweb/appserver.py @@ -160,6 +160,11 @@ async def on_receive(self, websocket, data): async def on_disconnect(self, websocket, close_code): self.task.cancel() + try: + await self.task + except asyncio.CancelledError: + pass + with redys.v2.AClient() as bus: await bus.unsubscribe(self.hr.hid.EVENT_RESPONSE_UPDATE) diff --git a/htagweb/server/__init__.py b/htagweb/server/__init__.py index 0ea0cd3..37f4f9b 100644 --- a/htagweb/server/__init__.py +++ b/htagweb/server/__init__.py @@ -306,11 +306,13 @@ async def startServer(): ################################################################################## async def stopServer(s): ################################################################################## - # clean all running process - await killall() + try: + # clean all running process + await killall() - # before stopping - s.stop() + finally: + # before stopping + s.stop() if __name__=="__main__": diff --git a/htagweb/server/client.py b/htagweb/server/client.py index fd7e2b5..92dcd2a 100644 --- a/htagweb/server/client.py +++ b/htagweb/server/client.py @@ -145,6 +145,6 @@ async def loop_tag_update(self, hrsocket, websocket): break await asyncio.sleep(0.1) except Exception as e: - print("**loop_tag_update, broken bus, will stop the loop_tag_update !**") + print(f"**loop_tag_update, broken bus, will stop the loop_tag_update (often a cancel error)!**") finally: await self._bus.unsubscribe(event) \ No newline at end of file