You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am using ScreenCaptureKit to capture screenshots and when I run two or more instances of the python script in parallel, the capture process silently hangs until I close all but one.
Simplified example that captures a screenshot every 2s:
importloggingimporttimefromAppKitimportNSBitmapImageFileTypePNG, NSBitmapImageRepfromScreenCaptureKitimport (
SCContentFilter,
SCScreenshotManager,
SCShareableContent,
SCStreamConfiguration,
)
defcapture_screenshot(save_path: str):
defshareable_content_completion_handler(shareable_content, error):
content_filter=SCContentFilter.alloc().initWithDisplay_excludingApplications_exceptingWindows_(
shareable_content.displays()[0], [], []
)
configuration=SCStreamConfiguration.alloc().init()
SCScreenshotManager.captureImageWithFilter_configuration_completionHandler_(
content_filter, configuration, capture_image_completion_handler
)
defcapture_image_completion_handler(image, error):
bitmap_rep=NSBitmapImageRep.alloc().initWithCGImage_(image)
png_data=bitmap_rep.representationUsingType_properties_(
NSBitmapImageFileTypePNG, None
)
png_data.writeToFile_atomically_(save_path, True)
logging.info(f"Screenshot saved at {save_path}")
SCShareableContent.getShareableContentWithCompletionHandler_(
shareable_content_completion_handler
)
time.sleep(1) # use a threading.event here but it's not necessary for this exampledefmain():
logging.basicConfig(level=logging.DEBUG)
whileTrue:
curr_time_s=time.strftime("%Y-%m-%d_%H-%M-%S")
capture_screenshot(save_path=f"screenshot_{curr_time_s}.png")
time.sleep(2)
If this is the only python script doing this, it works fine. If you run another instance of it in parallel (i.e. multiple apps open), both hang silently until you close all but one. Any ideas why and/or direction to take to debug/workaround? Thanks!
Running Python 3.12 on M1 Pro 14.5
The text was updated successfully, but these errors were encountered:
I am using ScreenCaptureKit to capture screenshots and when I run two or more instances of the python script in parallel, the capture process silently hangs until I close all but one.
Simplified example that captures a screenshot every 2s:
If this is the only python script doing this, it works fine. If you run another instance of it in parallel (i.e. multiple apps open), both hang silently until you close all but one. Any ideas why and/or direction to take to debug/workaround? Thanks!
Running Python 3.12 on M1 Pro 14.5
The text was updated successfully, but these errors were encountered: