From d2cc7490136e3b7d3f9eb93632b572087d093ba2 Mon Sep 17 00:00:00 2001 From: manatlan Date: Thu, 12 Oct 2023 12:52:31 +0200 Subject: [PATCH] minor changes --- example.py | 6 +++--- htagweb/appserver.py | 3 ++- htagweb/server/__init__.py | 8 -------- htagweb/server/client.py | 5 +++-- 4 files changed, 8 insertions(+), 14 deletions(-) diff --git a/example.py b/example.py index 2222e9c..b244b60 100644 --- a/example.py +++ b/example.py @@ -80,12 +80,12 @@ def test(o): self <= Tag.button("B",_onclick=test) - - +async def serve(req): + return await req.app.handle(req,Jo,http_only=True,parano=True) #------------------------------------------------------ from htagweb import SimpleServer,AppServer app=AppServer( App, timeout_inactivity=0 ) -app.add_route("/jo", lambda req: req.app.handle(req,Jo,http_only=True,parano=True) ) +app.add_route("/jo", serve) if __name__=="__main__": #~ import logging diff --git a/htagweb/appserver.py b/htagweb/appserver.py index 7b93024..64e8ea7 100644 --- a/htagweb/appserver.py +++ b/htagweb/appserver.py @@ -147,7 +147,7 @@ async def on_connect(self, websocket): await websocket.accept() # add the loop to tag.update feature - asyncio.ensure_future(self.hr.loop_tag_update(self, websocket)) + self.task = asyncio.create_task(self.hr.loop_tag_update(self, websocket)) async def on_receive(self, websocket, data): if self.is_parano: @@ -159,6 +159,7 @@ async def on_receive(self, websocket, data): await self._sendback( websocket, json.dumps(actions) ) async def on_disconnect(self, websocket, close_code): + self.task.cancel() 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 414c275..0ea0cd3 100644 --- a/htagweb/server/__init__.py +++ b/htagweb/server/__init__.py @@ -309,17 +309,9 @@ async def stopServer(s): # clean all running process await killall() - # before stopping s.stop() - bus=redys.v2.AClient() - while 1: - try: - await bus.ping() - except: - break - await asyncio.sleep(0.1) if __name__=="__main__": # asyncio.run( hrserver() ) diff --git a/htagweb/server/client.py b/htagweb/server/client.py index 8e6f31f..fd7e2b5 100644 --- a/htagweb/server/client.py +++ b/htagweb/server/client.py @@ -144,6 +144,7 @@ async def loop_tag_update(self, hrsocket, websocket): if not can: break await asyncio.sleep(0.1) - except: + except Exception as e: print("**loop_tag_update, broken bus, will stop the loop_tag_update !**") - + finally: + await self._bus.unsubscribe(event) \ No newline at end of file