ponty / pyscreenshot

Python screenshot library, replacement for the Pillow ImageGrab module on Linux.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ImageGrab.grab() function blocks code

muzunpostalci opened this issue · comments

Hi,
My code starts to get blocked at second invocation of
im = ImageGrab.grab()

If I add childprocess=False parameter as discussed at #38, it no longer blocks the code but it does not take the screenshot.

FYI, I have tracked the issue to these lines. Started to face this issue after adding these lines to my code and deleting them fixes the problem;

import gi
gi.require_version('Wnck', '3.0')
from gi.repository import Wnck
commented

I can reproduce the bug:

import gi
gi.require_version('Gdk', '3.0')
from gi.repository import Gdk
import pyscreenshot as ImageGrab
im = ImageGrab.grab(backend='pygdk3')
im = ImageGrab.grab(backend='pygdk3')
Gdk-Message: 15:51:32.984: x.py: Fatal IO error 0 (Success) on X server :0.

I found the answer here:
https://stackoverflow.com/questions/9989475/python-multiprocessing-with-2-gtk-windows
"multiprocessing.Process creates new processes using fork() instead of exec(). This means that each sub-process shares the same file handles as its parent, including those that connect it to the X server. The crash is caused because multiple processes are trying to communicate with the server simultaneously over the same connection."

commented

Fixed by setting childprocess default value to False.