Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6220fec

Browse files
committed
Add GIL Release to flush_events in macosx backend
Closes #28387
1 parent df148ee commit 6220fec

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/_macosx.m

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@ static int wait_for_stdin() {
8080

8181
// continuously run an event loop until the stdin_received flag is set to exit
8282
while (!stdin_received && !stdin_sigint) {
83+
// This loop is similar to the main event loop and flush_events which have
84+
// Py_[BEGIN|END]_ALLOW_THREADS surrounding the loop.
85+
// This should not be necessary here because PyOS_InputHook releases the GIL for us.
8386
while (true) {
8487
NSEvent *event = [NSApp nextEventMatchingMask: NSEventMaskAny
8588
untilDate: [NSDate distantPast]
@@ -383,6 +386,9 @@ static CGFloat _get_device_scale(CGContextRef cr)
383386
// to process, breaking out of the loop when no events remain and
384387
// displaying the canvas if needed.
385388
NSEvent *event;
389+
390+
Py_BEGIN_ALLOW_THREADS
391+
386392
while (true) {
387393
event = [NSApp nextEventMatchingMask: NSEventMaskAny
388394
untilDate: [NSDate distantPast]
@@ -393,6 +399,9 @@ static CGFloat _get_device_scale(CGContextRef cr)
393399
}
394400
[NSApp sendEvent:event];
395401
}
402+
403+
Py_END_ALLOW_THREADS
404+
396405
[self->view displayIfNeeded];
397406
Py_RETURN_NONE;
398407
}

0 commit comments

Comments
 (0)