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

Skip to content

macOS: Check for display availability when looking for backends #27761

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

QuLogic
Copy link
Member

@QuLogic QuLogic commented Feb 8, 2024

PR summary

This checks NSScreen::mainScreen similar to checking $DISPLAY/$WAYLAND_DISPLAY on Linux.

Fixes #26292

PR checklist

@QuLogic QuLogic added this to the v3.9.0 milestone Feb 8, 2024
@QuLogic QuLogic mentioned this pull request Feb 8, 2024
1 task
@tacaswell
Copy link
Member

I can confirm that this:

  • logged in (but locked) with screen plugged in -> True
  • logged in (but locked) with the hdmi unplugged -> True
  • logged out -> False

@tacaswell
Copy link
Member

Running the tests on this branch locally without a user logged in to the desktop (so launched via ssh) I get:

ERROR lib/matplotlib/tests/test_backend_macosx.py::test_cached_renderer - ImportError: Cannot load backend 'macosx' which requires the 'macosx' interactive framework, as 'headless' is currently running
ERROR lib/matplotlib/tests/test_backend_macosx.py::test_savefig_rcparam - ImportError: Cannot load backend 'macosx' which requires the 'macosx' interactive framework, as 'headless' is currently running

This suggests that what is going on the CI is slightly different than not having a display?

@QuLogic
Copy link
Member Author

QuLogic commented Feb 8, 2024

On Actions, the display does appear to exist, according to the results from #27723:

mainScreen: Built-in Display (1920.000000x1080.000000)+0.000000+0.000000 @8
deepestScreen: Built-in Display (1920.000000x1080.000000)+0.000000+0.000000 @8
Available screens: 1
    0: Built-in Display (1920.000000x1080.000000)+0.000000+0.000000 @8

For your failures, I think that's because the macOS tests don't have a skip, so I hadn't added one (only modified existing ones.)

@QuLogic QuLogic marked this pull request as ready for review February 8, 2024 21:24
@QuLogic QuLogic requested a review from greglucas February 8, 2024 21:24
@tacaswell
Copy link
Member

I tried re-running the failed mac3.11 jobs.

@QuLogic
Copy link
Member Author

QuLogic commented Feb 9, 2024

Looking at https://stackoverflow.com/questions/71954472/tkinter-crashes-on-ipython-but-not-in-python-on-a-m1-mac I think this might be because NSApplicationLoad messes with Tkinter somehow. I thought they were shared instances, but there must be something Tkinter is doing that confuses it if we create one ourselves.

@QuLogic
Copy link
Member Author

QuLogic commented Feb 9, 2024

Ah, here's a full explanation:

  • Both pyglet and Tk use AppKit to implement their GUI
  • AppKit uses an NSApplication class, and in particular a singleton instance of that class, to represent the application, which will get instantiated during application startup
  • The Tk library uses a sublclass of NSApplication with additional functionality (TkApplication).
  • When pyglet is started first the NSApplication singleton is an instance of NSApplication and not of TkApplication, but Tk's implementation assumes that the singleton is an instance of TkApplicationo.

but substitute the new code written here for pyglet above.

AFAICT from Googling though, we need the NSApplication instance to be sure that the NSScreen attributes are filled, though I've not tested it out myself.

Can you check if it works without the NSApplicationLoad?

@QuLogic QuLogic marked this pull request as draft February 9, 2024 07:35
@QuLogic QuLogic modified the milestones: v3.9.0, v3.10.0 Apr 2, 2024
@QuLogic QuLogic modified the milestones: v3.10.0, future releases Oct 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: macOS backend run by non-logged-in user crashes in Ventura
3 participants