pyqt / python-qt5

Unofficial PyQt5 via PyPI for Python 2.7 64-bit on Windows
GNU General Public License v3.0
280 stars 77 forks source link

Inheriting from QWebEnginePage, won't run in a loop, what am I doing wrong? #44

Open h5rdly opened 5 years ago

h5rdly commented 5 years ago

Hi,

I'm trying to run this snippet on Manjaro linux, Python 3.7.2, PyQt 5.12.2:

import sys
from PyQt5.QtWebEngineWidgets import QWebEnginePage
from PyQt5.QtWidgets import QApplication
from PyQt5.QtCore import QUrl
from time import sleep

class Page(QWebEnginePage):
    def __init__(self, url):
        self.app = QApplication(sys.argv)
        QWebEnginePage.__init__(self)
        self.html = ''
        self.loadFinished.connect(self._on_load_finished)
        self.load(QUrl(url))
        self.app.exec_()

    def _on_load_finished(self):
        sleep(7)
        self.html = self.toHtml(self.Callable)
        print('Load finished')

    def Callable(self, html_str):
        self.html = html_str
        self.app.quit()

for _ in range(4):
    Page('https://www.bbc.com/')

I get 2 iterations and then:

.
.
.
Received signal 11 SEGV_MAPERR 000000000250
.
.

However, if I paste the same code to say 10 different files, with: Page('https://www.bbc.com/') instead of a loop, and run them, it works fine.

Pardon my noobness, but why won't it work in a loop?

Thanks