How to terminate a disconnected client?
See original GitHub issueHi,
I’m having trouble cleanly terminating a disconnected client using an interrupt (ctrl+c
).
Given this example:
import socketio
import time
sio = socketio.Client()
@sio.on("connect")
def on_connect():
print("connected")
@sio.on("disconnect")
def on_disconnect():
print("disconnected")
sio.connect("http://localhost:8000")
try:
# sio.wait() # doesn't raise it, so have to implement it manually ;-)
while True:
time.sleep(1)
except KeyboardInterrupt:
print("handling interrupt...")
sio.disconnect()
print("done")
All goes well when issuing the interrupt when connected:
$ python client.py
connected
^Cdisconnected
handling interrupt...
done
$
But when performing the same procedure, after the client was disconnected from the server (by the server), the same interrupt handling code isn’t able to terminate the client cleanly, and the process continues, not returning to the console:
$ python client.py
connected
# stopping server now, after initial connected
disconnected
^Chandling interrupt...
done
The only way to terminate the process now is …
^Z
[1]+ Stopped python client.py
$ kill %1
[1]+ Terminated: 15 python client.py
Is there a proper way to terminate a client, when it’s in a disconnected state?
regards, Christophe VG
Issue Analytics
- State:
- Created 4 years ago
- Comments:12 (5 by maintainers)
Top Results From Across the Web
Disconnected sessions are not terminating when using the ...
Sessions started with Proficy WebSpace are not terminating when disconnected. The problem happens when using the Windows Desktop Client (full ...
Read more >HOW to terminate the thread when the client socket is closed
HI, We are developing a Socket application , Server socket will accept the client connections.
Read more >How to terminate or disconnect a virtual session in NoMachine
Disconnecting or 'suspending' the session is done by clicking the 'X' button in the upper corner of the window. Closing the window will ......
Read more >Terminating and Disconnecting Session - Documentation
Navigate to the session to kill in the sessions list. · Choose Kill Session or Disconnect Session on the shortcut menu or corresponding...
Read more >IntelliJ / WebStorm - Terminate vs Disconnect - Stack Overflow
Terminate causes the running process(es) to stop; Disconnect keeps the process running, but the IDE (debugger, etc.) ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@chrisdoehring Sounds good. Thank you, if you have any questions let me know!
Mr. Miguel - Thanks for that reply. I’m just good enough at Python to be dangerous, I’ll review this later and see if I get what you mean.