Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions lib/matplotlib/backends/backend_macosx.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,9 @@ def draw_idle(self):

def _single_shot_timer(self, callback):
"""Add a single shot timer with the given callback"""
# We need to explicitly stop and remove the timer after
# firing, otherwise segfaults will occur when trying to deallocate
# the singleshot timers.
def callback_func(callback, timer):
callback()
self._timers.remove(timer)
timer.stop()
timer = self.new_timer(interval=0)
timer.single_shot = True
timer.add_callback(callback_func, callback, timer)
Expand Down
5 changes: 5 additions & 0 deletions src/_macosx.m
Original file line number Diff line number Diff line change
Expand Up @@ -1741,6 +1741,11 @@ - (void)flagsChanged:(NSEvent *)event
repeats: !single
block: ^(NSTimer *timer) {
gil_call_method((PyObject*)self, "_on_timer");
if (single) {
// A single-shot timer will be automatically invalidated when it fires, so
// we shouldn't do it ourselves when the object is deleted.
self->timer = NULL;
}
}];
// Schedule the timer on the main run loop which is needed
// when updating the UI from a background thread
Expand Down