diff --git a/lib/matplotlib/backends/backend_macosx.py b/lib/matplotlib/backends/backend_macosx.py index a39f5b5b1497..726a2ada8425 100644 --- a/lib/matplotlib/backends/backend_macosx.py +++ b/lib/matplotlib/backends/backend_macosx.py @@ -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) diff --git a/src/_macosx.m b/src/_macosx.m index 3fac8b41f84e..eaf4f8292546 100755 --- a/src/_macosx.m +++ b/src/_macosx.m @@ -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