-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Catch exceptions that occur in callbacks. #7197
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
Conversation
Uncaught exceptions are fatal to PyQt5 so we catch anything that occurs in a callback of the canvas class. e.g. ``` from matplotlib import pyplot as plt plt.gca().figure.canvas.mpl_connect( "axes_enter_event", lambda event: 1 / 0) plt.show() ``` used to crash matplotlib upon entering the axes.
@@ -542,6 +542,21 @@ def process(self, s, *args, **kwargs): | |||
except ReferenceError: | |||
self._remove_proxy(proxy) | |||
|
|||
def safe_process(self, s, on_error, *args, **kwargs): |
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.
Is there any changes you will be calling with an on_error
different from traceback.print_exc
?
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.
Yes, close_event
completely silences out specific exception types.
We vendored and modified the callback registry at my day-job (https://github.com/NSLS-II/bluesky/blob/master/bluesky/utils.py#L159) to add a stateful flag to the control if callbacks are allowed to raise or not. I think that is a better option here as it would require less change to the code base, provides a way to go back to the previous behavior, and does not leave an 'orphaned' method on the callback registry. |
The problem of the flag you propose is that exceptions are completely swallowed. An alternative would be to replace the flag by a callback stored as an attribute... say Side note for @tacaswell: for your own implementation, given that it is Py3 only you could probably use |
@anntzer I agree, that is a better idea than a flag. |
👍 to the idea of using a callable attribute |
The problem is that we need a half-decent method for locally patching this attribute when needed. However, the only place where this needs to happen is in
(the earlier version wrapped |
The |
Closing in favor of #9063 |
Uncaught exceptions are fatal to PyQt5 so we catch anything that occurs
in a callback of the canvas class.
e.g.
used to crash matplotlib upon entering the axes.
More general than #7052.