Is this a proper way to delect disconnect inside a loop (socketio.AsyncNamespace) #1171
Answered
by
miguelgrinberg
4n1qz5skwv
asked this question in
Q&A
-
class IndexSio(socketio.AsyncNamespace):
async def on_connect(self, sid, *_, **__):
...
async def on_disconnect(self, sid, *_, **__):
...
async def on_start(self, sid):
while True:
try:
ddd = await self.get_session(sid)
except KeyError:
# Is this a safe place to assume that client has disconnected ?
break
print(f'{ddd=}') Hint: the comment (except block) |
Beta Was this translation helpful? Give feedback.
Answered by
miguelgrinberg
Apr 4, 2023
Replies: 1 comment 1 reply
-
The |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
4n1qz5skwv
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The
disconnect
event is invoked when a client disconnects. There is no need for you to repeatedly get the session just to see if that errors out. For example, you can use anEvent
object in youron_start
event handler for each client, which you signal from the disconnect handler.