On some sites (eg 118114.cn) problem and the application hangs forever. Debug shows that the problem in this code snippet:
while self.__loading:
if timeout > 0 and time.time() >= cancelAt:
raise RuntimeError("Request timed out on %s" % url)
while QApplication.hasPendingEvents():
QCoreApplication.processEvents()
Full version of the source code is available here (lines 270-2开发者_高级运维75)
Somehow Loading-event hangs and hasPendingEvents can not be False.
Most of the screenshots are created normally, but sometimes due to some URL drops my app: (
Does anyone know how to solve this problem and why the event hangs?
I'm also using webkit2png + Linux, and encountered the issue you've described when testing locally on my MacBook Pro. The issue appears to be that QApplication.hasPendingEvents() incorrectly returns True, and the while loop hangs. I worked around this issue by removing the while loop:
while self.__loading:
if timeout > 0 and time.time() >= cancelAt:
raise RuntimeError("Request timed out on %s" % url)
QCoreApplication.processEvents()
Note you'll also need to make this change in __WebkitRendererHelper.render in a couple of spots. Everything worked for me after making these changes- good luck.
Edit: I believe I solved this problem on the Linux side of things originally by upgrading the underlying QT library. The default version for Ubuntu 10.04 LTS (4.6.2) has a bug which is fixed in later versions. Here's my installation info:
Package: libqtcore4
State: installed
Automatically installed: yes
Version: 4:4.7.0-0ubuntu2~lucid1~ppa1
Priority: optional
Section: libs
Maintainer: Kubuntu Developers <kubuntu-devel@lists.ubuntu.com>
Uncompressed Size: 7,471k
Depends: libc6 (>= 2.9), libgcc1 (>= 1:4.1.1), libglib2.0-0 (>= 2.12.0), libstdc++6 (>= 4.1.1), zlib1g (>= 1:1.1.4)
Breaks: libqt4-core (< 4.4.0~beta1-1), libqt4-gui (< 4.4.0~beta1-1)
Replaces: libqt4-core (< 4.4.0~beta1-1), libqt4-gui (< 4.4.0~beta1-1)
Description: Qt 4 core module
Qt is a cross-platform C++ application framework. Qt's primary feature is its rich set of widgets that provide standard GUI
functionality.
The QtCore module contains core non-GUI functionality.
I upgraded libqtcore4 but that didn't fix it for me. I had to make the changes suggested by Jeremy to webkit2png.py
# aptitude show libqtcore4
Package: libqtcore4
State: installed
Automatically installed: no
Version: 4:4.7.2-0ubuntu6.1
around line 230 there are two calls to hasPendingEvents() also
229 while time.time() < waitToTime:
230 #while QApplication.hasPendingEvents():
231 QApplication.processEvents()
232
233 # Paint this frame into an image
234 #self._window.repaint()
235 #while QApplication.hasPendingEvents():
236 QApplication.processEvents()
processEvents() will run all pending events for up to a max of 3 seconds. It's working ok for me so far. The websites that would not render are now appearing without any problems. If you need longer than 3 seconds (busy server?) then the while loop on 235 needs a timeout.
Maybe there is a recurring timer? For example, a blinking cursor on a page will cause the events (timer fires, view invalidate, paint, ..) to be available continuously.
You probably need to insert a timeout logic so that while loop exits, if it is running for far too long already.
精彩评论