-
-
Notifications
You must be signed in to change notification settings - Fork 8.1k
BUG: raise when creating a MacOS FigureManager outside the main thread #30697
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
BUG: raise when creating a MacOS FigureManager outside the main thread #30697
Conversation
|
Huh. I need to come back to the to try to understand why the image comparison tests are failing on the Mac runners... |
actually on second look, I think these failures are happening on all PRs. I don't see the Windows failure here elsewhere but I don't see how it could be related. |
|
The windows failures are flaky timeouts, which are a known issue. The macOS image comparison failures are quite new but happen consistently across PRs. We haven’t had time to inspect them but they are unrelated to this PR. I’m sorry our CI is currently in a desolate state. |
|
Appears likely to be the Ghostscript version update as noted (re: fedora rawhide) here: #30624 At the very least the same two tests were affected |
|
I wonder if we should add #pragma nocoverage to the private subprocess helper classes so it doesn't look like codecoverage was less than it actually was in these. I can tell the subprocess test ran that function and tested it locally that it was getting hit. |
|
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. |
…ing a MacOS FigureManager outside the main thread)
…rker-threads BUG: raise when creating a MacOS FigureManager outside the main thread (cherry picked from commit 94def4e)
Backport PR #30697 on branch v3.10.x (BUG: raise when creating a MacOS FigureManager outside the main thread)
Fixes #30666
Currently matplotlib will crash due to an uncaught NSException if a worker thread tries to create a GUI window. Only the main thread can create GUIs in Cocoa. This is documented in the Cocoa docs under the "Application Kit Framework Thread Safety" section.
I added a new check to the beginning of
FigureManager_newthat bails with an exception if the thread is not the main thread. It turns out[NSThread isMainThread]is the builtin way to check for that in objC. I'm open to other more fine-grained approaches as well. I tried simply catching the exception seen in #30666, but that fails because subsequent Cocoa cleanup code segfaults. The only way I could find to avoid these segfaults was to avoid setting up any Cocoa state and bailing as early as possible as in this PR.Also added a test to make sure the correct exception gets raised. There's already a more generic UserWarning generated by the pyplot python implementation, so I added a
pytest.warnsfor that as well.