Skip to content
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

don't try to start a new event loop in WebAgg when in an ipykernel #24120

Merged
merged 3 commits into from Dec 16, 2022
Merged

don't try to start a new event loop in WebAgg when in an ipykernel #24120

merged 3 commits into from Dec 16, 2022

Conversation

zhizheng1
Copy link
Contributor

PR Summary

Use asyncio.get_running_loop() to check if a loop is already running. Only try to start a new one when there is no running loop.

Fixes #24119

PR Checklist

Tests and Styling

  • [N/A] Has pytest style unit tests (and pytest passes).
  • [N/A] Is Flake 8 compliant (install flake8-docstrings and run flake8 --docstring-convention=all).

Documentation

  • [N/A] New features are documented, with examples if plot related.
  • [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).
  • [N/A] Documentation is sphinx and numpydoc compliant (the docs should build without error).

@tacaswell tacaswell added this to the v3.7.0 milestone Oct 7, 2022
@tacaswell
Copy link
Member

I am a bit concerned about the asyncio vs tornado contrast. I do not recall of the top of my head when tornado rebased itself on top of asyncio (it was in the last few years, I think tornado 5 (?)), do we need to put a minimum on the supported versions of Tornado?

Can you comment on why this works? I'm surprised that we are able to automatically graft onto the existing tornado loop and run the communication over it....

@zhizheng1
Copy link
Contributor Author

I did a search and it seems it's been working since a very LONG time ago - see this issue #4042 from 2015 which had the same observation as mine. I think what this PR does is just those mentioned in the end of that issue - suppress the errors/exceptions about loop already running, and not touch what's already working.

@tacaswell
Copy link
Member

Tornado 5 is indeed when tornado started to use the asyscio event loop if found, there is a static method IOLoop.current() which is how the running loop is injected into all of the relevant places where it needs to be found.

We already document tornado >=5 so I think there is no further work needed here (but in a notebook you should probably be using ipympl).

@QuLogic QuLogic merged commit 12402f4 into matplotlib:main Dec 16, 2022
@QuLogic
Copy link
Member

QuLogic commented Dec 16, 2022

Thanks @zhizheng1! Congratulations on your first PR to Matplotlib 🎉 We hope to hear from you again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[ENH]: don't try to start a new event loop in WebAgg when in an ipykernel
3 participants