-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Allow threads during macos event loop #27755
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow threads during macos event loop #27755
Conversation
I had a 14.1 system, confirmed the code in #27720 worked as expected, then updating the mac to 14.3 it failed and then using this branch it works again. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this makes sense. We have two separate entry-points to the runloops.
- Through
pyplot.show()
which starts the mainloop and has an[NSApp run]
that is surrounded by the ALLOW_THREADS calls:matplotlib/lib/matplotlib/backends/backend_macosx.py
Lines 180 to 183 in c2aa4ee
def start_main_loop(cls): # Set up a SIGINT handler to allow terminating a plot via CTRL-C. with _allow_interrupt_macos(): _macosx.show() - Through
pyplot.pause()
which starts an eventloop (not necessarily the mainloop), which is not surrounded by the ALLOW_THREADS currently and this PR implements:matplotlib/lib/matplotlib/backends/backend_macosx.py
Lines 113 to 117 in c2aa4ee
def start_event_loop(self, timeout=0): # docstring inherited # Set up a SIGINT handler to allow terminating a plot via CTRL-C. with _allow_interrupt_macos(): self._start_event_loop(timeout=timeout) # Forward to ObjC implementation.
So, I think this makes sense as well. I can confirm that I upgraded to 14.3 and this fixes it. Thanks @ksunden!
…755-on-v3.8.x Backport PR #27755 on branch v3.8.x (Allow threads during macos event loop)
@meeseeksdev backport to v3.7.x |
Owee, I'm MrMeeseeks, Look at me. There seem to be a conflict, please backport manually. Here are approximate instructions:
And apply the correct labels and milestones. Congratulations — you did some good work! Hopefully your backport PR will be tested by the continuous integration and merged soon! Remember to remove the If these instructions are inaccurate, feel free to suggest an improvement. |
…ent_loop Allow threads during macos event loop (cherry picked from commit b50843d)
PR summary
Add START/END "ALLOW THREADS" macros to the event loop code.
This breaks the deadlock, which allows the GIL to be acquired in an alternate thread.
It is not clear to me why this is MacOS version dependent, but this does appear to work and seems sensible to me.
Closes #27720
PR checklist