From 1004e032a4f102e88ec4a19153233c21f6123458 Mon Sep 17 00:00:00 2001 From: Thomas A Caswell Date: Thu, 14 Mar 2024 13:39:33 -0400 Subject: [PATCH] Backport PR #27875: macosx: Clean up single-shot timers correctly --- lib/matplotlib/backends/backend_macosx.py | 4 ---- src/_macosx.m | 5 +++++ 2 files changed, 5 insertions(+), 4 deletions(-) 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 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