-
-
Notifications
You must be signed in to change notification settings - Fork 573
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
No message on client's end when disconnecting #594
Comments
Yeah, there are a couple of problems in your code and you've also found a bug. First of all, in the server you are calling The background task in your client is at risk of race conditions. Your while loop will end when the client is disconnected, but if the disconnect happens in the middle of a loop iteration the thread may end up making a Socket.IO call after the connection is gone. See the "How to Kill a Python Thread" article on my blog for ideas on how to stop the thread before your disconnect. In the client you'd normally want to call The disconnect handler not being called is a bug in this package actually, so it is not your fault. The handler is invoked when the disconnect is initiated by the server, but it looks like I missed it when it is the client initiating. I'll fix that. |
Thanks for such detailed explanation of what's going on! 😮 I have few more questions Sir:
So the disconnect handler calls
Thanks for noticing. I haven't really touched threads so far in my learning. Would a
So it's enough to call |
No. The disconnect handler is invoked as a result of the client disconnecting. A client can disconnect on their own (i.e. closing the browser tab) or calling a
That's a bad solution that may or may not work, since due to different timings the error can be different every time. What exception are you going to catch? Catching all exceptions is a bad practice that can hide bugs in your applications, so that is not a good option. As I said before, I have a blog post on this topic, check that out.
You have to call disconnect when you are done. If you call it from your background thread, the |
What's the problem?
I wrote a simple client and server. Client sends platform data to server, and server sends a number of connected clients. When the client disconnects nothing is being printed out (client's
disconnect()
function seems to be not called). I just started learning this package so it might be just me not understanding some part of it.What I've done so far
sio.disconnect()
function both from client.py and server.pyTalk is cheap, show me the code
Server
Client
The text was updated successfully, but these errors were encountered: