macOS Rework: Timers - #32369
Draft
iccir wants to merge 21 commits into
Draft
macOS Rework: Timers#32369iccir wants to merge 21 commits into
iccir wants to merge 21 commits into
Conversation
Obj-C classes: MatplotlibAppDelegate -> MPLLegacyAppDelegate Window -> MPLLegacyWindow View -> MPLLegacyView NavigationToolbar2Handler -> MPLLegacyNavigationToolbar2Handler
This branch has not been deployed
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
Important
This PR depends on #32161 and will appear larger than it really is until #32161 is merged. To view the actual changes in this PR, compare macos-staging → macos-pr-timer.
This PR adds an MPLTimer class.
Previously,
TimerTypewrapped both anNSTimerobject and ashouldInvalidateboolean. It contained logic to handle scheduling and invalidation. This is contrary to our new design where "_macos.m" is a simple glue layer with logic living in the wrappedMPL*class.MPLTimerattempts to mimic the behavior of aQTimeras much as possible in order to ease our timer consistency efforts.Threading Changes
The previous implementation of
_macosx.Timerwould schedule theNSTimeron the main thread. From research (#27527, #25553, #5675), this behavior was needed due todraw_idleusing timers internally. Asdraw_idlenow usesdispatch_async, we can re-examine this behavior.I am use to "callbacks are called in the execution context from which the timer was created/scheduled/started". I am not use to the concept of timers being used for inter-thread messaging.
Consider the following code:
Whether or not this is allowed depends on the backend:
Per discussion in #31968, I am inclined to make any usage of timers on a worker thread raise an error. I believe that this should be extended to other backends as well (see #32352).
A future pull request will raise an error when crossing into Objective-C from Python (except for a select list of methods). That is out of scope for this pull request.
Thread-safe Variant
In the event that we someday want a thread-safe variant of MPLTimer, here's the relevant code:
Thread-safe MPLTimer.h
Thread-safe MPLTimer.m
AI Disclosure
PR quality check