PyQt4达到的最大xserver客户端数量

时间:2015-08-11 07:28:57

标签: python linux pyqt4 qwebview xserver

我有一个python脚本。脚本从网页截取屏幕截图。我使用xvfb来运行它。经过大约240次迭代后,我收到了一条消息:

  

"到达script.py的最大客户端数:无法连接到X.   服务器:99"。

我希望有超过3 000次迭代。

有没有办法在不停止脚本的情况下关闭xserver连接以避免错误?

Script.py有一个for循环并使用以下代码:

webkit.py:

 import sys
 import time
 from PyQt4.QtCore import QUrl
 from PyQt4.QtGui import QApplication, QImage, QPainter
 from PyQt4.QtWebKit import QWebView
 from PyQt4 import QtCore

 class Screenshot(QWebView):

    def __init__(self, width, height):
        self.app = QApplication(sys.argv)
        QWebView.__init__(self)
        self._loaded = False
        self.loadFinished.connect(self.load_finished)
        self.width = int(width)
        self.height = int(height)
        self.app.deleteLater()


    def capture(self, url, output_file):
        self.load(QUrl(url))
        self.wait_load()
        frame = self.page().mainFrame()
        self.page().setViewportSize(QtCore.QSize(self.width, self.height))
        image = QImage(self.page().viewportSize(), QImage.Format_ARGB32)
        painter = QPainter(image)
        frame.render(painter)
        painter.end()
        image.save(output_file)

        return output_file

    def wait_load(self, delay=1):
        while not self._loaded:
            self.app.processEvents()
            time.sleep(delay)
        self._loaded = False

    def load_finished(self):
        self._loaded = True

0 个答案:

没有答案
相关问题