Hi Everyone<br><br>I&#39;ve created a python wrapper for qt browser, but if I run it many times, it&#39;ll crash in few cases with segfaults like following:<br>[ 9939.720253] python[13090] general protection ip:7f43c853c96e sp:7fffbe6d0de0 error:0 in QtCore.so[7f43c8406000+188000]<br>



What&#39;s wrong with the code? Timers? Javascript? Something else? Or it&#39;s just unstable Qt browser?<br><br>Ubuntu 9.10 (karmic); PyQt version 4.6-1; Qt 4.5.3really4.5.2-0ubuntu1<br>---------------------------------------------------- wrapper ---------------------------------------------------------------<br>


import logging<br>from PyQt4.QtCore import SIGNAL, QObject, QUrl, QTimer, QString<br>from PyQt4.QtGui import QApplication<br>from PyQt4.QtWebKit import QWebView, QWebPage, QWebSettings<br><br>class WebKitPage(QWebPage):<br>


    def __init__(self, user_agent):<br>        QWebPage.__init__(self)<br>        self.user_agent = user_agent<br>    def userAgentForUrl(self, url):<br>        return self.user_agent<br>    def javaScriptConsoleMessage(self, message, line, source):<br>


        <a href="http://logging.info" target="_blank">logging.info</a>(&quot;WebKitPage &gt; js line %s at %s, message %s&quot;, line, source, message)<br><br>class WebKitBrowser:<br>    def __init__(self, parsers):<br>        self.app = QApplication([])<br>


        self.url = self.timer = None<br>        self.parsers = parsers<br>        self.page = WebKitPage(&quot;Test user agent&quot;)<br>        self.browser = QWebView()<br>        QObject.connect(self.browser, SIGNAL(&quot;loadFinished(bool)&quot;), self.load_finished)<br>


        self.browser.get_js_str = self.get_js_str<br>        self.browser.show()<br>        self.browser.resize(800,600)<br>        self.browser.setPage(self.page)<br>        self.browser.settings().setAttribute(QWebSettings.AutoLoadImages, False)<br>


<br>    def get_js_str(self, frame, js, arg = None):<br>        jsqs = QString(js)<br>        if arg != None: jsqs = jsqs.arg(arg)<br>        return unicode(frame.evaluateJavaScript(jsqs).toString())<br><br>    def timer_shot(self):<br>


        self.timer_stop()<br>        self.browser.stop()<br><br>    def timer_start(self, timeout):<br>        self.timer = QTimer()<br>        QObject.connect(self.timer, SIGNAL(&quot;timeout()&quot;), self.timer_shot)<br>


        self.timer.start(timeout * 1000)<br><br>    def timer_stop(self):<br>        if self.timer:<br>            self.timer.stop()<br>            self.timer = None<br><br>    def load_finished(self, stat):<br>        <a href="http://logging.info" target="_blank">logging.info</a>(&quot;WebKitBrowser &gt; Load finished&quot;)<br>


        self.timer_stop()<br>        self.status = stat and &quot;success&quot; or &quot;timeout&quot;<br>        for parser in self.parsers:<br>            parser.run(self.browser)<br>        self.real_url = self.browser.get_js_str(self.browser.page().mainFrame(), &quot;location.href&quot;)<br>


        <a href="http://logging.info" target="_blank">logging.info</a>(&quot;WebKitBrowser &gt; Status %s, Real url %s&quot;, self.status, self.real_url)<br>        self.app.exit()<br><br>    def get(self, url, timeout = 60):<br>

        <a href="http://logging.info" target="_blank">logging.info</a>(&quot;WebKitBrowser &gt; Loading %s&quot;, url)<br>
        self.browser.stop()<br>        self.status = &quot;loading&quot;<br>        self.timer_start(timeout)<br>        self.browser.load(QUrl(url))<br>        self.app.exec_()<br>        return self.status<br><br>class LinkParser:<br>


    def extract_links(self, frame):<br>        frame.evaluateJavaScript(&quot;var anchors = document.getElementsByTagName(&#39;a&#39;);&quot;)<br>        count, ok = frame.evaluateJavaScript(&quot;anchors.length;&quot;).toInt()<br>


        for i in range(0, count):<br>            <a href="http://logging.info" target="_blank">logging.info</a>(&quot;LinkParser &gt; %s&quot;, self.browser.get_js_str(frame, &quot;anchors[%1].href&quot;, i))<br><br>    def run(self, browser):<br>


        self.browser = browser<br>        self.extract_links(self.browser.page().mainFrame())<br>        for frame in self.browser.page().mainFrame().childFrames():<br>            self.extract_links(frame)<br><br>if __name__ == &quot;__main__&quot;:<br>


    logging.basicConfig(level=logging.DEBUG)<br>    b = WebKitBrowser([ LinkParser() ])<br>    b.get(&quot;<a href="http://google.com/" target="_blank">http://google.com/</a>&quot;)<br>    b.get(&quot;<a href="http://youtube.com/" target="_blank">http://youtube.com/</a>&quot;, 1)<br>


    b.get(&quot;<a href="http://google.com/" target="_blank">http://google.com/</a>&quot;)<br><br>