FIX: macosx, always put timers on main thread#25553
Merged
tacaswell merged 1 commit intomatplotlib:mainfrom Mar 28, 2023
Merged
FIX: macosx, always put timers on main thread#25553tacaswell merged 1 commit intomatplotlib:mainfrom
tacaswell merged 1 commit intomatplotlib:mainfrom
Conversation
The main thread is the one that is running when started, so we should put all timers we control on that thread. Otherwise we need to start and control runloops on the other threads which may or may not be started. This is particularly important for draw_idle() calls that may be sent from a separate thread where work was being done, but the draw should happen on the main thread still.
tacaswell
approved these changes
Mar 26, 2023
Member
|
This makes sense from a general "how should event loops work" point of view and I tested this manually (worked as advertised). |
QuLogic
approved these changes
Mar 28, 2023
1 task
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR Summary
The main thread is the one that is running when started, so we should put all timers we control on that thread. Otherwise, we need to start and control runloops on the other threads which may or may not be started. This is particularly important for
draw_idle()calls that may be sent from a separate thread where work was being done, but the draw should happen on the main thread still.closes #5675
To test, you can use the example from #5675 with some updates from other comments in there (save to file and run in interactive mode
python -i mac-threading-test.py. Previously, the canvas would never be updated and freeze after the fact due to the extra thread waiting to have a runloop started and capture the draw events that were sent. There is a slight concern that we could hang the GUI event loop if we send too many timer events, but this seems to work just fine in practice here when I'm running this example I can change over to the pan tool and still move the canvas even while receiving the events.PR Checklist
Documentation and Tests
pytestpasses)Release Notes
.. versionadded::directive in the docstring and documented indoc/users/next_whats_new/.. versionchanged::directive in the docstring and documented indoc/api/next_api_changes/next_whats_new/README.rstornext_api_changes/README.rst