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 documentation for run_forever() states that run_forever() will return a bool that will be True if there was an exception, or False if KeyboardInterrupt was caught, or if the websocket was closed (I assume from the server side.)
This does not reflect the current code which catches KeyboardInterrupt and Exception together in the same block. In my testing, when I send CTRL+C at the terminal (the parent process), it's also sent to all child processes (of which, in my case, websocket-client is one), and the return value of run_forever() is always True, so I can't differentiate between the KeyboardInterrupt sent from the terminal and an actual Exception that occurred naturally in the child process.
(Additionally, this line should use repr(e) because it does not even log that KeyboardInterrupt was the reason for the teardown since str(e) is blank for KeyboardInterrupt.)
But, in my opinion, websocket-client should not meddle with KeyboardInterrupt at all as that is the main process's concern. The way it is now, I can't catch KeyboardInterrupt and handle it gracefully from the main process (the one actually at the terminal, vs a background process which is what websocket-client is for me) because it's caught at a lower level in this library. I believe this to be bad practice.
I propose that KeyboardInterrupt be removed from the aforementioned line so that it can be caught at the outer level. I don't see the reason for catching KeyboardInterrupt there and it makes the code less modular since now this signal is absorbed by the websocket-client library can't be customised.
As it stands, the following simple example shows how it's not possible to handle KeyboardInterrupt at the main level. It is expected that KeyboardInterrupt can always be handled like this.
try:
client.run_forever()
except KeyboardInterrupt:
# never happens, because run_forever() catches KeyboardInterrupt itself
print("interrupt received, do something...")
In addition, the documentation should be updated to reflect the new situation once an agreement is made on this issue.
The text was updated successfully, but these errors were encountered:
The documentation for
run_forever()
states thatrun_forever()
will return a bool that will beTrue
if there was an exception, orFalse
ifKeyboardInterrupt
was caught, or if the websocket was closed (I assume from the server side.)This does not reflect the current code which catches
KeyboardInterrupt
andException
together in the same block. In my testing, when I send CTRL+C at the terminal (the parent process), it's also sent to all child processes (of which, in my case, websocket-client is one), and the return value ofrun_forever()
is alwaysTrue
, so I can't differentiate between theKeyboardInterrupt
sent from the terminal and an actualException
that occurred naturally in the child process.(Additionally, this line should use
repr(e)
because it does not even log thatKeyboardInterrupt
was the reason for the teardown sincestr(e)
is blank forKeyboardInterrupt
.)But, in my opinion, websocket-client should not meddle with
KeyboardInterrupt
at all as that is the main process's concern. The way it is now, I can't catchKeyboardInterrupt
and handle it gracefully from the main process (the one actually at the terminal, vs a background process which is what websocket-client is for me) because it's caught at a lower level in this library. I believe this to be bad practice.I propose that
KeyboardInterrupt
be removed from the aforementioned line so that it can be caught at the outer level. I don't see the reason for catchingKeyboardInterrupt
there and it makes the code less modular since now this signal is absorbed by the websocket-client library can't be customised.As it stands, the following simple example shows how it's not possible to handle
KeyboardInterrupt
at the main level. It is expected thatKeyboardInterrupt
can always be handled like this.In addition, the documentation should be updated to reflect the new situation once an agreement is made on this issue.
The text was updated successfully, but these errors were encountered: