Skip to content

Commit 850bf04

Browse files
authored
Merge pull request #27875 from QuLogic/fix-macosx-timer
macosx: Clean up single-shot timers correctly
2 parents 7164087 + 9eda24f commit 850bf04

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

lib/matplotlib/backends/backend_macosx.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,9 @@ def draw_idle(self):
6767

6868
def _single_shot_timer(self, callback):
6969
"""Add a single shot timer with the given callback"""
70-
# We need to explicitly stop and remove the timer after
71-
# firing, otherwise segfaults will occur when trying to deallocate
72-
# the singleshot timers.
7370
def callback_func(callback, timer):
7471
callback()
7572
self._timers.remove(timer)
76-
timer.stop()
7773
timer = self.new_timer(interval=0)
7874
timer.single_shot = True
7975
timer.add_callback(callback_func, callback, timer)

src/_macosx.m

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1746,6 +1746,11 @@ - (void)flagsChanged:(NSEvent *)event
17461746
repeats: !single
17471747
block: ^(NSTimer *timer) {
17481748
gil_call_method((PyObject*)self, "_on_timer");
1749+
if (single) {
1750+
// A single-shot timer will be automatically invalidated when it fires, so
1751+
// we shouldn't do it ourselves when the object is deleted.
1752+
self->timer = NULL;
1753+
}
17491754
}];
17501755
// Schedule the timer on the main run loop which is needed
17511756
// when updating the UI from a background thread

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy