BoboTiG / python-mss

An ultra fast cross-platform multiple screenshots module in pure Python using ctypes.
https://pypi.org/project/mss/
MIT License
998 stars 89 forks source link

CoreGraphics.CGWindowListCreateImage() failed when running as a system process. #133

Open brummetj opened 4 years ago

brummetj commented 4 years ago

General information:

Description of the warning/error

I'm trying to run my python program as a launchd daemon process since its a REST flask app that needs to be running at all times and needs to have the ability to relaunch if the macOS gets rebooted.

One of the endpoints allows me to grab a screenshot of the current monitor. I really like to use your library for the lower level performance... but running as a launchd it seems that this will always fail to create the Image from the CoreGraphics.

CoreGraphics.CGWindowListCreateImage() failed.

Otherwise it works as long as it's being executed as the user, or even executing sudo on the python script works fine.

Am i missing something with System context and CoreGraphics API's ?

Upvote & Fund

Fund with Polar

BoboTiG commented 4 years ago

In "Utilities > Console", do you have an error that may help us? I think there is a security thing involved. Could you post the launchd code please?

brummetj commented 4 years ago

Thanks for the prompt response.

I've been rummaging through the console logs and can't seem to find anything directly related to the CoreGraphics besides some CoreCapture crash logs which doesn't pertain anything related to the CoreGraphics module.

Do you have an idea on what error message could possibly look like ? I also think this is a security thing involved as well..

The launchd code is a 0. And runs fine, but once I hit that endpoint /screenshot which utilizes your mss library it will fail to get that screen capture with CoreGraphics.CGWindowListCreateImage() failed.

I have a potential work around idea of executing a subprocess script which will stdout the binary image as a different user.

brummetj commented 4 years ago

Update:

I tried launching a forked screenshot process and executing as another user and will still get a failure with the CoreGraphics module... will need to look until other solutions until this is fixed

BoboTiG commented 4 years ago

Could you post what is needed to reproduce locally? -- Mickaël Schoentgen Site web : http://www.tiger-222.fr

ishandutta2007 commented 3 years ago

Same error whenever I run it from cron. Works fine when triggered explicitly from terminal

BoboTiG commented 3 years ago

I do not have a macOS machine anymore. If someone wants to give a hand, that would be great :)