1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
| import sys
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
from PyQt5.QtWebEngineWidgets import QWebEnginePage
import time
urlb = "https://www.google.fr/"
class Worker(QRunnable, QWebEnginePage):
'''
Worker thread
'''
def __init__(self, url):
super(Worker, self).__init__()
self.url = url
def _on_load_finished(self):
print("tfouuu")
self.html = self.toHtml(self.Callable)
print('Load finished')
def Callable(self, html_str):
self.html = html_str
@pyqtSlot()
def run(self):
print("a")
time.sleep(2)
print(self.url)
print("b")
QWebEnginePage.__init__(self)
print("c")
self.html = ''
self.loadFinished.connect(self._on_load_finished)
self.load(QUrl(url))
print("d")
class MainWindow(QMainWindow):
def __init__(self, *args, **kwargs):
self.threadpool = QThreadPool()
print("Multithreading with maximum %d threads" % self.threadpool.maxThreadCount())
super(MainWindow, self).__init__(*args, **kwargs)
worker = Worker(urlb)
worker2 = Worker(urlb)
self.threadpool.start(worker)
self.threadpool.start(worker2)
app = QApplication([])
window = MainWindow()
app.exec_() |
Partager