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

Appearance settings

Commit 1fccb5c

Browse filesBrowse files
committed
FIX/ENH: macos: dispatch timer tasks asynchronously to the main loop
Previously, the timers were dependent on the length of time it took for the timer callback to execute. This dispatches the callback to the task queue to avoid synchronously waiting on long-running callback tasks.
1 parent 2dfb933 commit 1fccb5c
Copy full SHA for 1fccb5c

File tree

1 file changed

+11
-12
lines changed
Filter options

1 file changed

+11
-12
lines changed

‎src/_macosx.m

Copy file name to clipboardExpand all lines: src/_macosx.m
+11-12Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1770,19 +1770,18 @@ - (void)flagsChanged:(NSEvent *)event
17701770
}
17711771

17721772
// hold a reference to the timer so we can invalidate/stop it later
1773-
self->timer = [NSTimer timerWithTimeInterval: interval
1774-
repeats: !single
1775-
block: ^(NSTimer *timer) {
1776-
gil_call_method((PyObject*)self, "_on_timer");
1777-
if (single) {
1778-
// A single-shot timer will be automatically invalidated when it fires, so
1779-
// we shouldn't do it ourselves when the object is deleted.
1780-
self->timer = NULL;
1781-
}
1773+
self->timer = [NSTimer scheduledTimerWithTimeInterval: interval
1774+
repeats: !single
1775+
block: ^(NSTimer *timer) {
1776+
dispatch_async(dispatch_get_main_queue(), ^{
1777+
gil_call_method((PyObject*)self, "_on_timer");
1778+
if (single) {
1779+
// A single-shot timer will be automatically invalidated when it fires, so
1780+
// we shouldn't do it ourselves when the object is deleted.
1781+
self->timer = NULL;
1782+
}
1783+
});
17821784
}];
1783-
// Schedule the timer on the main run loop which is needed
1784-
// when updating the UI from a background thread
1785-
[[NSRunLoop mainRunLoop] addTimer: self->timer forMode: NSRunLoopCommonModes];
17861785

17871786
exit:
17881787
Py_XDECREF(py_interval);

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.