Catch exceptions that occur in callbacks.#7197
Catch exceptions that occur in callbacks.#7197anntzer wants to merge 1 commit intomatplotlib:masterfrom
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.
| except ReferenceError: | ||
| self._remove_proxy(proxy) | ||
|
|
||
| def safe_process(self, s, on_error, *args, **kwargs): |
There was a problem hiding this comment.
Is there any changes you will be calling with an on_error different from traceback.print_exc?
There was a problem hiding this comment.
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.