From 29637c5b45b345bf443035f1bc47a8194e92b3cb Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Wed, 26 Jun 2024 15:24:00 -0400 Subject: [PATCH] Backport PR #28398: Add GIL Release to flush_events in macosx backend --- src/_macosx.m | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/_macosx.m b/src/_macosx.m index 656d502fa17c..fda928536ab5 100755 --- a/src/_macosx.m +++ b/src/_macosx.m @@ -77,6 +77,9 @@ static int wait_for_stdin() { // continuously run an event loop until the stdin_received flag is set to exit while (!stdin_received && !stdin_sigint) { + // This loop is similar to the main event loop and flush_events which have + // Py_[BEGIN|END]_ALLOW_THREADS surrounding the loop. + // This should not be necessary here because PyOS_InputHook releases the GIL for us. while (true) { NSEvent *event = [NSApp nextEventMatchingMask: NSEventMaskAny untilDate: [NSDate distantPast] @@ -380,6 +383,9 @@ static CGFloat _get_device_scale(CGContextRef cr) // to process, breaking out of the loop when no events remain and // displaying the canvas if needed. NSEvent *event; + + Py_BEGIN_ALLOW_THREADS + while (true) { event = [NSApp nextEventMatchingMask: NSEventMaskAny untilDate: [NSDate distantPast] @@ -390,6 +396,9 @@ static CGFloat _get_device_scale(CGContextRef cr) } [NSApp sendEvent:event]; } + + Py_END_ALLOW_THREADS + [self->view displayIfNeeded]; Py_RETURN_NONE; }