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

FIX/ENH: macos: dispatch timer tasks asynchronously to the main loop#29030

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

Closed

Conversation

greglucas
Copy link
Contributor

PR summary

Previously, the timers were dependent on the length of time it took for the timer callback to execute. This dispatches the callback to the main thread's task queue to avoid synchronously waiting on long-running callback tasks.

Note that I didn't add any tests here because there is inconsistency between backends, so other backends fail for these assertions currently. I've opened up an issue to discuss that:#29029

On main, this script prints every 2 secondscallback time + timer interval, with this PR it prints every secondmax(callback time, timer interval).

importtimeimportmatplotlib.pyplotaspltfig=plt.figure()defon_timer():print(time.ctime())time.sleep(1)timer=fig.canvas.new_timer(interval=1000)timer.add_callback(on_timer)timer.start()fig.canvas.start_event_loop(10)

PR checklist

Previously, the timers were dependent on the length of time it took forthe timer callback to execute. This dispatches the callback tothe task queue to avoid synchronously waiting on long-running callbacktasks.
// we shouldn't do it ourselves when the object is deleted.
self->timer = NULL;
}
self->timer = [NSTimer scheduledTimerWithTimeInterval: interval
Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

This automatically schedules the timer on the main runloop for us.
https://developer.apple.com/documentation/foundation/timer/2091889-scheduledtimer

self->timer = [NSTimer scheduledTimerWithTimeInterval: interval
repeats: !single
block: ^(NSTimer *timer) {
dispatch_async(dispatch_get_main_queue(), ^{
Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

This is the major change here. We are dispatching our event asynchronously (so as to not sequentially depend on the callback processing time), but putting it onto the main thread's queue.

@greglucas
Copy link
ContributorAuthor

closing in favor of doing this all in a consolidated PR:#29062

@greglucasgreglucas deleted the macos-timer-async branchNovember 1, 2024 17:49
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers
No reviews
Assignees
No one assigned
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

2 participants
@greglucas@QuLogic

[8]ページ先頭

©2009-2025 Movatter.jp