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

Skip to content

Commit 29637c5

Browse files
QuLogicmeeseeksmachine
authored andcommitted
Backport PR #28398: Add GIL Release to flush_events in macosx backend
1 parent e392b59 commit 29637c5

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
@@ -77,6 +77,9 @@ static int wait_for_stdin() {
7777

7878
// continuously run an event loop until the stdin_received flag is set to exit
7979
while (!stdin_received && !stdin_sigint) {
80+
// This loop is similar to the main event loop and flush_events which have
81+
// Py_[BEGIN|END]_ALLOW_THREADS surrounding the loop.
82+
// This should not be necessary here because PyOS_InputHook releases the GIL for us.
8083
while (true) {
8184
NSEvent *event = [NSApp nextEventMatchingMask: NSEventMaskAny
8285
untilDate: [NSDate distantPast]
@@ -380,6 +383,9 @@ static CGFloat _get_device_scale(CGContextRef cr)
380383
// to process, breaking out of the loop when no events remain and
381384
// displaying the canvas if needed.
382385
NSEvent *event;
386+
387+
Py_BEGIN_ALLOW_THREADS
388+
383389
while (true) {
384390
event = [NSApp nextEventMatchingMask: NSEventMaskAny
385391
untilDate: [NSDate distantPast]
@@ -390,6 +396,9 @@ static CGFloat _get_device_scale(CGContextRef cr)
390396
}
391397
[NSApp sendEvent:event];
392398
}
399+
400+
Py_END_ALLOW_THREADS
401+
393402
[self->view displayIfNeeded];
394403
Py_RETURN_NONE;
395404
}

0 commit comments

Comments
 (0)