-
Notifications
You must be signed in to change notification settings - Fork 373
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
Python: don't catch KeyboardInterrupt
and SystemExit
#4333
Conversation
There are little reasons to emit a warning and keep-on going when a KeyboardInterrupt exception is received (i.e. was sent by the user). I propose to let this one be passed to the client even in non strict mode
KeyboardInterrupt
to the user when emitted in log function.KeyboardInterrupt
to the user when emitted in log function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch - thanks for the PR!
@@ -205,7 +205,7 @@ def __exit__( | |||
exc_tb: TracebackType | None, | |||
) -> bool: | |||
try: | |||
if exc_type is not None and not strict_mode(): | |||
if exc_type is not None and exc_type is not KeyboardInterrupt and not strict_mode(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this is the better fix - this will ignore both KeyboardInterrupt
and SystemExit
if exc_type is not None and exc_type is not KeyboardInterrupt and not strict_mode(): | |
if exc_type is Exception and not strict_mode(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If that's the intention, perhaps worth adding a comment to the effect as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@emilk well spotted (I had forgotten about that Exception
vs. BaseException
thing). I fixed the code with the correct issubclass
check + a comment.
KeyboardInterrupt
to the user when emitted in log function.KeyboardInterrupt
and SystemExit
Changes were made, but needed to unblock merge.
What
Currently, the python sdk will catch any exception raised inside a rerun log function and surface it as a printed warning rather than an exception to the client. This makes sense to avoid crashing the app for a mistake in the argument of the log function. This can be disabled with the "strict mode" through an environment variables.
However, there are little reasons to emit a warning and keep-on going when a
KeyboardInterrupt
exception is received. The official doc states even that this kind of exception are better not being caught at all:I propose to have a special case for this type of exception, and throwing them back to the client even in non strict mode.
I tested, that Ctrl-C now interrupts some test program instantly instead of being unreliable before (because sometime catches inside rerun log).
Checklist