PIL:ImageGrab.grab()失败-OSError:屏幕抓取失败

时间:2019-03-12 23:08:59

标签: python python-imaging-library

我有一个脚本通过PIL ImageGrab不断获取屏幕截图。代码如下:

def updateScreenshot(self):
        self.screen = ImageGrab.grab()

updateScreenshot()函数经常被调用,例如每秒2-3次。脚本运行良好,直到我重构了该类并将所有与屏幕快照相关的代码移动到封装了所有屏幕快照逻辑的外部模型类中。现在我的主类有:

self.screenshotService = ScreenshotService()

在它的__init_ _函数中。然后,ScreenshotService将触发updateScreenshot()updateScreenshot()的前几次尝试仍然有效,之后发生以下错误:

File "...\screenshotService.py", line 15, in updateScreenshot
    self.screen = ImageGrab.grab()
  File "C:\Python34\lib\site-packages\PIL\ImageGrab.py", line 31, in grab
    size, data = grabber()

我发现:

  1. https://github.com/python-pillow/Pillow/issues/1601
  2. Take a screenshot via a python script. [Linux]

但是这些并不能真正指出我正确的方向。

有什么想法吗?谢谢。

Python 3.4, PIL:5.4.1

0 个答案:

没有答案