You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The normal behavior of Python applications is to be able to hit Ctrl+C to interrupt the main thread. However, pynng breaks this expectation for Socket.recv() and Socket.send(). I'm not confident that I've found the underlying issue in nng yet, but I believe (and could be wrong, I haven't attempted a patch yet) that this is related to the use of some pthread_cond_wait, rather than actually restarting the recv() system calls.
The text was updated successfully, but these errors were encountered:
Okay, it turns out that this cannot be solved at the Python level in any reasonable way I can think of. I was attempting to register a signal handler for SIGINT to examine the stack frame and close any pynng sockets, but since the handler will only run in Python's main thread that was a nonstarter; the whole reason we send SIGINT is because the main thread is in a blocking call!
We could do something painful like send all calls to recv() and send() to a thread pool, but it seems needlessly inefficient; the cure is worse than the disease.
The good news is that the async API doesn't have this problem! i.e. the following code does the right thing, raising a KeyboardInterrupt exception when SIGINT is received:
The situation for Windows is worse than POSIX, because at least on POSIX if upstream changes things will get better. On Windows, to get nice behavior we'll have to have hacks no matter what, it seems; see this PR that does... something... to make Ctrl+C work on Windows. I haven't looked at it closely yet and... it's time for bed. :-)
The normal behavior of Python applications is to be able to hit Ctrl+C to interrupt the main thread. However, pynng breaks this expectation for
Socket.recv()
andSocket.send()
. I'm not confident that I've found the underlying issue in nng yet, but I believe (and could be wrong, I haven't attempted a patch yet) that this is related to the use of somepthread_cond_wait
, rather than actually restarting the recv() system calls.The text was updated successfully, but these errors were encountered: