8000 Fix lack of delay in initial firing of timer on osx (Fixes #11985) · matplotlib/matplotlib@ceb3e50 · GitHub
[go: up one dir, main page]

Skip to content

Commit ceb3e50

Browse files
committed
Fix lack of delay in initial firing of timer on osx (Fixes #11985)
One of the arugments when creating a timer on OSX is the time of first fire. We were passing 0, which puts the time in the past, which means it fires as soon as possible. Change to calculate what that time should be.
1 parent 30746c5 commit ceb3e50

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/_macosx.m

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2422,6 +2422,7 @@ static void context_cleanup(const void* info)
24222422
CFRunLoopTimerRef timer;
24232423
CFRunLoopTimerContext context;
24242424
double milliseconds;
2425+
CFAbsoluteTime firstFire;
24252426
CFTimeInterval interval;
24262427
PyObject* attribute;
24272428
PyObject* failure;
@@ -2446,12 +2447,15 @@ static void context_cleanup(const void* info)
24462447
PyErr_SetString(PyExc_AttributeError, "Timer has no attribute '_single'");
24472448
return NULL;
24482449
}
2450+
// Need to tell when to first fire this timer, so get the current time
2451+
// and add an interval.
2452+
interval = milliseconds / 1000.0;
2453+
firstFire = CFAbsoluteTimeGetCurrent() + interval;
24492454
switch (PyObject_IsTrue(attribute)) {
24502455
case 1:
24512456
interval = 0;
24522457
break;
2453-
case 0:
2454-
interval = milliseconds / 1000.0;
2458+
case 0: // Set by default above
24552459
break;
24562460
case -1:
24572461
default:
@@ -2475,7 +2479,7 @@ static void context_cleanup(const void* info)
24752479
context.copyDescription = NULL;
24762480
context.info = attribute;
24772481
timer = CFRunLoopTimerCreate(kCFAllocatorDefault,
2478-
0,
2482+
firstFire,
24792483
interval,
24802484
0,
24812485
0,

0 commit comments

Comments
 (0)
0