8000 macosx: Clean up single-shot timers correctly · matplotlib/matplotlib@60c1d5b · GitHub
[go: up one dir, main page]

Skip to content

Commit 60c1d5b

Browse files
committed
macosx: Clean up single-shot timers correctly
The `NSTimer` docs state that a non-repeating (aka single-shot in our terms) timer is invalidated after if fires. This means that we should not do it ourselves, and in fact it appears that the pointer itself is no longer valid, so we would be passing an `invalidate` message to a random object or segfault. I believe this is why `test_other_signal_before_sigint` is marked as flaky as well, as it uses a single-shot timer and a segfault is recorded in the XPASS log.
1 parent 2d5e293 commit 60c1d5b

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

lib/matplotlib/tests/test_backends_interactive.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -764,8 +764,6 @@ def test_other_signal_before_sigint(env, target, kwargs, request):
764764
backend = env.get("MPLBACKEND")
765765
if not backend.startswith(("qt", "macosx")):
766766
pytest.skip("SIGINT currently only tested on qt and macosx")
767-
if backend == "macosx":
768-
request.node.add_marker(pytest.mark.xfail(reason="macosx backend is buggy"))
769767
proc = _WaitForStringPopen(
770768
[sys.executable, "-c",
771769
inspect.getsource(_test_other_signal_before_sigint_impl) +

src/_macosx.m

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1741,6 +1741,11 @@ - (void)flagsChanged:(NSEvent *)event
17411741
repeats: !single
17421742
block: ^(NSTimer *timer) {
17431743
gil_call_method((PyObject*)self, "_on_timer");
1744+
if (single) {
1745+
// A single-shot timer will be automatically invalidated when it fires, so
1746+
// we shouldn't do it ourselves when the object is deleted.
1747+
self->timer = NULL;
1748+
}
17441749
}];
17451750
// Schedule the timer on the main run loop which is needed
17461751
// when updating the UI from a background thread

0 commit comments

Comments
 (0)
0