Skip to content

Adds error handling around install_repl_displayhook #25870

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 1 commit into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion lib/matplotlib/pyplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,11 @@ def draw_if_interactive() -> None:
matplotlib.backends.backend = newbackend # type: ignore[attr-defined]

# Make sure the repl display hook is installed in case we become interactive.
install_repl_displayhook()
try:
install_repl_displayhook()
except NotImplementedError as err:
_log.warning("Fallback to a different backend")
raise ImportError from err


def _warn_if_gui_out_of_main_thread() -> None:
Expand Down
15 changes: 15 additions & 0 deletions lib/matplotlib/tests/test_backends_interactive.py
Original file line number Diff line number Diff line change
Expand Up @@ -623,6 +623,21 @@ def test_blitting_events(env):
assert 0 < ndraws < 5


def _fallback_check():
import IPython.core.interactiveshell as ipsh
import matplotlib.pyplot
ipsh.InteractiveShell.instance()
matplotlib.pyplot.figure()


def test_fallback_to_different_backend():
pytest.importorskip("IPython")
# Runs the process that caused the GH issue 23770
# making sure that this doesn't crash
# since we're supposed to be switching to a different backend instead.
response = _run_helper(_fallback_check, timeout=_test_timeout)


def _impl_test_interactive_timers():
# A timer with <1 millisecond gets converted to int and therefore 0
# milliseconds, which the mac framework interprets as singleshot.
Expand Down
Loading