Skip to content

Commit

Permalink
Backport PR matplotlib#28398: Add GIL Release to flush_events in maco…
Browse files Browse the repository at this point in the history
…sx backend
  • Loading branch information
QuLogic authored and meeseeksmachine committed Jun 26, 2024
1 parent e392b59 commit 29637c5
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/_macosx.m
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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]
Expand All @@ -390,6 +396,9 @@ static CGFloat _get_device_scale(CGContextRef cr)
}
[NSApp sendEvent:event];
}

Py_END_ALLOW_THREADS

[self->view displayIfNeeded];
Py_RETURN_NONE;
}
Expand Down

0 comments on commit 29637c5

Please sign in to comment.