Skip to content

When no gui event loop is running, propagate callback exceptions. #15270

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

Merged
merged 3 commits into from
Oct 20, 2019

Conversation

anntzer
Copy link
Contributor

@anntzer anntzer commented Sep 15, 2019

CallbackRegistry currently defaults to suppressing exceptions that occur
in callbacks (since #9063) because they cause PyQt5 to abort() the program with no
chance of even catching the exception, but such a behavior is annoying
when writing tests involving callbacks (e.g., mplcursors), because in
that case we actually want to see whether an exception occurred, and
typically fail the test in that case.

Instead we can detect whether a GUI event loop is currently running and
propagate the exception if none is running.

Part of the patch is just moving _get_running_interactive_framework
from backends to cbook, so that cbook keeps its property of being
importable independent of the rest of mpl.

PR Summary

PR Checklist

  • Has Pytest style unit tests
  • Code is Flake 8 compliant
  • New features are documented, with examples if plot related
  • Documentation is sphinx and numpydoc compliant
  • Added an entry to doc/users/next_whats_new/ if major new feature (follow instructions in README.rst there)
  • Documented in doc/api/api_changes.rst if API changed in a backward-incompatible way

@anntzer anntzer force-pushed the cbr-exceptions branch 2 times, most recently from f3ecbd0 to 5cd9481 Compare September 15, 2019 23:52
@jklymak jklymak added this to the v3.3.0 milestone Oct 8, 2019
Copy link
Member

@efiring efiring left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, subject to passing test after rebase.

@anntzer
Copy link
Contributor Author

anntzer commented Oct 8, 2019

rebased

@anntzer anntzer force-pushed the cbr-exceptions branch 2 times, most recently from 7ae415a to c476c4d Compare October 8, 2019 20:42
CallbackRegistry currently defaults to suppressing exceptions that occur
in callbacks because they cause PyQt5 to abort() the program with no
chance of even catching the exception, but such a behavior is annoying
when writing tests involving callbacks (e.g., mplcursors), because in
that case we actually want to see whether an exception occurred, and
typically fail the test in that case.

Instead we can detect whether a GUI event loop is currently running and
propagate the exception if none is running.

Part of the patch is just moving `_get_running_interactive_framework`
from `backends` to `cbook`, so that `cbook` keeps its property of being
importable independent of the rest of mpl.
@tacaswell
Copy link
Member

The drop in test coverage was due to there being a dead branch in the test code now that the default case is now in it's own test.

@dstansby dstansby merged commit 1d597cf into matplotlib:master Oct 20, 2019
@anntzer anntzer deleted the cbr-exceptions branch October 21, 2019 09:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants