python-mss icon indicating copy to clipboard operation
python-mss copied to clipboard

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

Open brummetj opened this issue 4 years ago • 6 comments

General information:

  • OS name: macOS Catalina
  • OS version: 10.15
  • OS architecture: 64 bits
  • Resolutions:
    • Monitor 1: 1920x1080
  • Python version: 3.7.3
  • MSS version: 3.2.0

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 ?

brummetj avatar Nov 14 '19 05:11 brummetj

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?

BoboTiG avatar Nov 14 '19 09:11 BoboTiG

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 avatar Nov 15 '19 18:11 brummetj

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

brummetj avatar Nov 15 '19 21:11 brummetj

Could you post what is needed to reproduce locally?

Mickaël Schoentgen Site web : http://www.tiger-222.fr

BoboTiG avatar Nov 15 '19 23:11 BoboTiG

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

ishandutta2007 avatar Sep 05 '21 22:09 ishandutta2007

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

BoboTiG avatar Sep 06 '21 05:09 BoboTiG