Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged

Conversation

turnipseason
Copy link
Contributor

PR summary

Closes#23770. Starting an ipython session with InteractiveShell led to a crash with NotImplementedError being raised. An ImportError needed to be raised from that, allowing for continuation with a different backend.

PR checklist

Copy link

@github-actionsgithub-actionsbot left a comment

Choose a reason for hiding this comment

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

Thank you for opening your first PR into Matplotlib!

If you have not heard from us in a while, please feel free to ping@matplotlib/developers or anyone who has commented on the PR. Most of our reviewers are volunteers and sometimes things fall through the cracks.

You can also join uson gitter for real-time discussion.

For details on testing, writing docs, and our review process, please seethe developer guide

We strive to be a welcoming and open project. Please follow ourCode of Conduct.

install_repl_displayhook()
try:
install_repl_displayhook()
except ImportError as err:
Copy link
Member

Choose a reason for hiding this comment

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

Can we catch theNotImplemented error here instead and make no changes toinstall_repl_displayhook?

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Sure, I changed it! In light of your next comment -- is this still relevant in general (should I amend my PR)?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, I think the technical question is if we

  • eat the error
  • warn
  • re-raiseImportError

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Clearly I'm no authority on this, but warning and re-raising seem pretty logical to do because it just crashes otherwise.

I also didn't fully understand your comment -- like why should there be no GUI at all with block=True/sleep enabled. The couple of examples I tried all seemed to work (switching to a different backend and continuing as intended). I'm very likely missing something, but is the expected behavior here something different?

@tacaswell
Copy link
Member

Now that I see this implemented as I described I'm no longer sure this is best approach 😞 .

I still think the analysis of the problem in#23770 (comment) is correct, however what I did not consider when I wrote that is that it only applies if the user wants to doplt.ion() and work in "interactive mode". If they are happy to not have windows pop-up and be live while they type (and either useplt.show(block=True) orplt.sleep(10) to get temporarily live figures) then this change will prevent users from getting GUIs at all.

On the other hand if we just catch and eat theNotImplemented exception inswitch_backends (maybe printing a warning) then we enable users use GUI backends with this limited IPython shell, even if its usage is degraded.

With the plain Python shell this sort of "un-managed" situation is possible so from a parity point of view preventing it is bad. On the other hand, currently the GUI backends do not work with this version of the IPython shell so we are not actually taking anything away, but are making it so things will automatically import and do something sensible.

I can see arguments both ways and think either one would be acceptable, but we should consider both options.

@tacaswelltacaswell modified the milestones:v3.8.0,v3.7.2May 12, 2023
@tacaswell
Copy link
Member

So with this change I think it will fallback toagg because we can get IPython to setup up the input hook so that

plt.ion()plt.show(block=False)

work. On the other hand, we could just eat the exception and give the user a partially functional GUI.

@melissawm
Copy link
Member

Hi@turnipseason@tacaswell do we need more discussion here or is there a clear path forward?

@turnipseason do you need help with the current test failures?

@turnipseason
Copy link
ContributorAuthor

Hi@turnipseason@tacaswell do we need more discussion here or is there a clear path forward?

@turnipseason do you need help with the current test failures?

Hi@melissawm ! Sorry for not replying sooner. I tried understanding what's going on but still don't quite get it, so I'm not sure I can contribute much to the discussion, unfortunately. When I tried running it, both (eating/not eating the exception) ways worked just fine and neither defaulted to the non-interactive background. They also never seemed to enter the interactive python mode though (I couldn't type in the console, even though the input was captured and shown after I closed the GUI), so I'm not sure if I just wrote something incorrectly.

With regards to the test failures -- yes, I think I do.
They seem to be coming from the tests I wrote, since it calls for IPython in the subprocess and the tests fail with a ModuleNotFoundError because there's no IPython. Should I check for the existence of IPython in the subprocess and skip the test somehow if is isn't found since this issue concerns IPython in the first place? Or rewrite them completely?

@ksunden
Copy link
Member

@turnipseason

yes you can usepytest.importorskip("IPython")

I would also perhaps suggest using the_run_helper for running your code as a subprocess, that will allow the code to look like a normal python function, rather than being included as strings.

turnipseason reacted with thumbs up emoji

@ksunden
Copy link
Member

Did the rebase, which was just caused by a comment being reflowed adjacent to some changed lines

ksunden
ksunden previously approved these changesSep 12, 2023
@ksundenksunden dismissed theirstale reviewSeptember 12, 2023 21:20

Test failures on azure macos are the newly added test

@ksundenksunden modified the milestones:v3.8.0,v3.8.1Sep 12, 2023
Comment on lines 639 to 640
response = _run_helper(_fallback_check, timeout=_test_timeout)
assert response != subprocess.CalledProcessError
Copy link
Member

Choose a reason for hiding this comment

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

The run helper passescheck=True, which causesCalledProcessError to be raised; I don't understand why this is checking the return value, which should be asubprocess.CompletedProcess.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

You're right. I just thought we had to check for it. Should I leave the test at this, then? It seems to do the same thing (fail without the fix, pass with the fix).

deftest_fallback_to_different_backend():pytest.importorskip("IPython")_run_helper(_fallback_check,timeout=_test_timeout)

Copy link
Member

Choose a reason for hiding this comment

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

All exceptions are errors; theassert can never be False, so there's no need for it.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Ok then, thank you, I'll leave it without the assert!

@ksunden
Copy link
Member

Test failures on Azure MacOS are still the newly added test in the latest revision.

Additionally, needs a rebase for the meson build system change to fix Circle.

@QuLogic
Copy link
Member

Do you have any thoughts on this PR,@ianthomas23?

@ianthomas23
Copy link
Member

Do you have any thoughts on this PR,@ianthomas23?

I think it is a somewhat unusual use case that would be reasonable to "won't fix" but given that the fix is simple, localised and evidently a good thing to do anyway then I would approve it. It needs a rebase but that looks relatively straightforward.

One complication is that there is another unprotected use ofinstall_repl_displayhook inpyplot.ion():

stack=ExitStack()
stack.callback(ionifisinteractive()elseioff)
matplotlib.interactive(True)
install_repl_displayhook()
returnstack

and we cannot repeat the fix here as we are not switching a backend. But I don't think it should stop this PR.

 # This is a combination of 3 commits.Fixes the issue 23770 and adds a test in test_backends_interactive.pyChanged the test to skip when IPython can't be imported and use _run_helper for the subprocess.Removed the redundant assert statement.
@QuLogicQuLogic changed the titleAdds error handling around install_repl_displayhook and call to enable_gui in pyplot; adds a test in test_backends_interactive.Adds error handling around install_repl_displayhookNov 16, 2024
@QuLogicQuLogicforce-pushed thebug-fix-for-issue-23770 branch from5c468c3 to321b769CompareNovember 16, 2024 01:03
@QuLogic
Copy link
Member

OK, then I've rebased and squashed.

@QuLogicQuLogic marked this pull request as ready for reviewNovember 16, 2024 01:04
@ianthomas23
Copy link
Member

I'd be happy to approve this but there are some CI failures that may or may not be related.

@QuLogic
Copy link
Member

It looks like the new test is hitting the long-standingactions/setup-python#649

Copy link
Member

@ianthomas23ianthomas23 left a comment

Choose a reason for hiding this comment

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

Approved as CI failure unrelated.

@tacaswelltacaswell merged commitfa92cf9 intomatplotlib:mainDec 16, 2024
43 of 45 checks passed
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@tacaswelltacaswelltacaswell left review comments

@QuLogicQuLogicQuLogic left review comments

@github-actionsgithub-actions[bot]github-actions[bot] left review comments

@ianthomas23ianthomas23ianthomas23 approved these changes

@ksundenksundenksunden left review comments

Assignees
No one assigned
Projects
Milestone
v3.11.0
Development

Successfully merging this pull request may close these issues.

[Bug]: crash due to backend issue in ipython session started explicitly with InteractiveShell
6 participants
@turnipseason@tacaswell@melissawm@ksunden@QuLogic@ianthomas23

[8]ページ先頭

©2009-2025 Movatter.jp