Skip to content

Commit

Permalink
minor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
manatlan committed Oct 12, 2023
1 parent f04a379 commit d2cc749
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 14 deletions.
6 changes: 3 additions & 3 deletions example.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion htagweb/appserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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)

Expand Down
8 changes: 0 additions & 8 deletions htagweb/server/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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() )
Expand Down
5 changes: 3 additions & 2 deletions htagweb/server/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit d2cc749

Please sign in to comment.