8000 Fix interrupting GTK on plain Python by QuLogic · Pull Request #21530 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

Fix interrupting GTK on plain Python #21530

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
Nov 11, 2021
Merged

Conversation

QuLogic
Copy link
Member
@QuLogic QuLogic commented Nov 3, 2021

PR Summary

When the application is shut down, it's intended that all windows are closed. This shutdown event is also run if interrupted with Ctrl-C. But then the main loop is no longer running, and windows do not notice the close event sent to them.

In IPython, the input hook runs the loop and allows the windows to close down. But in plain Python, there is no input hook integration, and the windows sit around in limbo without accepting any events.

Absent any new input hook integrations, the workaround is to iterate the main loop on interrupt.

PR Checklist

  • Has pytest style unit tests (and pytest passes).
  • Is Flake 8 compliant (run flake8 on changed files to check).
  • [n/a] New features are documented, with examples if plot related.
  • [n/a] Documentation is sphinx and numpydoc compliant (the docs should build without error).
  • Conforms to Matplotlib style conventions (install flake8-docstrings and run flake8 --docstring-convention=all).
  • [n/a] New features have an entry in doc/users/next_whats_new/ (follow instructions in README.rst there).
  • [n/a] API changes documented in doc/api/next_api_changes/ (follow instructions in README.rst there).

@QuLogic QuLogic added this to the v3.5.0 milestone Nov 3, 2021
@anntzer
Copy link
Contributor
anntzer commented Nov 3, 2021

The difference in behavior I can see is that after MPLBACKEND=gtk... python -c "from pylab import *; plot(); show()', ctrl-c previously exited with a traceback but exits without a traceback with this PR (or was the goal something else, and did you just forget to re-raise the KeyboardInterrupt?). I don't have a super-strong opinion as to whether a traceback should be displayed, but right now wx displays no traceback and qt and tk do display one, do you want to make this consistent everywhere?

@QuLogic
Copy link
Member Author
QuLogic commented Nov 3, 2021

Arg yes, I just forgot the raise. Perils of working on multiple machines.

When the application is shut down, it's intended that all windows are
closed. This shutdown event is also run if interrupted with Ctrl-C.
But then the main loop is no longer running, and windows do not notice
the close event sent to them.

In IPython, the input hook runs the loop and allows the windows to close
down. But in plain Python, there is no input hook integration, and the
windows sit around in limbo without accepting any events.

Absent any new input hook integrations, the workaround is to iterate the
main loop on interrupt.
@anntzer
Copy link
Contributor
anntzer commented Nov 3, 2021

Then it's not clear to me what this is trying to achieve? (i.e., is there an example that didn't work previously and is fixed by this?)

8000

@QuLogic
Copy link
Member Author
QuLogic commented Nov 3, 2021

You need to be in an interactive shell to see the difference. Previously, interrupting a plain Python shell would return control to the shell but leave the windows in limbo. In IPython, they would be closed because the input hook runs the event loop.

Copy link
Contributor
@anntzer anntzer left a comment

Choose a reason for hiding this comment

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

Ah yes, that works (althought this seems needed only on gtk3, for me, but this seems harmless to have on gtk4 as well).

@anntzer
Copy link
Contributor
anntzer commented Nov 3, 2021

On a related note, looks like on wxagg+plain python shell, ctrl-c actually quits the entire process; is that something you want to fix as well?

@QuLogic
Copy link
Member Author
QuLogic commented Nov 3, 2021

I did take a look; there is a clearSigInt option in wx.App which is on by default. If you disable it, then Ctrl-C does nothing and only prints out a (unhandled) exception when the _onPaint handler is run, and everything keeps running. I did not look much deeper, so it's possible we'd have to manually setup a handler like the Qt case to get it to work the same.

@anntzer
Copy link
Contributor
anntzer commented Nov 4, 2021

Ah, if that's just defaukt toolkit behavior, I think we should just leave things as they are (perhaps with a note somewhere) and let people configure this as they see fit.

@tacaswell tacaswell merged commit 98f005c into matplotlib:main Nov 11, 2021
meeseeksmachine pushed a commit to meeseeksmachine/matplotlib that referenced this pull request Nov 11, 2021
tacaswell added a commit that referenced this pull request Nov 11, 2021
…530-on-v3.5.x

Backport PR #21530 on branch v3.5.x (Fix interrupting GTK on plain Python)
@QuLogic QuLogic deleted the gtk-interrupt branch November 11, 2021 22:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
0