question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to terminate a disconnected client?

See original GitHub issue

Hi,

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:closed
  • Created 4 years ago
  • Comments:12 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
miguelgrinbergcommented, May 27, 2019

@chrisdoehring Sounds good. Thank you, if you have any questions let me know!

0reactions
mark-zarandicommented, Jan 7, 2020

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found