PyQt5 handle parallel QWebEngineView page loadings?
I have tried some suggestions on the net but couldn't succeed yet. Not sure if it is possible but will explain what I am trying to achieve.
I have a MainWindow which has the following method. And a button initializes three instances of browser widgets beforehand.
def handleSearches(self):
# do the search
browseThreads =
for idx, browser in enumerate(self.browsers):
browseThreads.append(BrowseThread(browser, self.data["options"][idx]))
for browseThread in browseThreads:
browseThread.start()
Where the browser as defined QWidget like following;
class Browser(QtWidgets.QWidget):
def __init__(self, title):
super().__init__()
self.gridLayout = QtWidgets.QGridLayout(self)
self.gridLayout.setObjectName("gridLayout")
self.webView = QWebEngineView()
self.webView.setUrl(QtCore.QUrl("https://www.google.com.tr"))
# some codes
def search(self, question, candidate, mode):
self.candidate = candidate
url = "https://www.google.com.tr/search?q={}".format(urllib.parse.quote_plus(candidate))
self.webView.setUrl(QtCore.QUrl(url))
def find_text(self, text):
soup = BS(self.src,'lxml')
# some source code alteration here
self.webView.page().setHtml(str(soup), self.webView.page().requestedUrl())
def on_page_load(self):
self.webView.page().toHtml(self.on_source_fetched)
def on_source_fetched(self, data):
self.src = data
self.find_text(self.candidate)
My Thread class is defined like following,
class BrowseThread (QThread):
def __init__(self, browser, searchString):
QThread.__init__(self)
self.searchString = searchString
self.browser = browser
def run(self):
self.search_text(self.searchString)
def search_text(self, text):
self.browser.search(text, '', 1)
What I am trying to achieve is to search different strings in parallel in 3 instances without blocking anything. Thread didn't work I guess because the browser widget GUI needs an update. How to do this?
Thanks.
python-3.x pyqt5 python-multithreading qthread qwebengineview
|
show 4 more comments
I have tried some suggestions on the net but couldn't succeed yet. Not sure if it is possible but will explain what I am trying to achieve.
I have a MainWindow which has the following method. And a button initializes three instances of browser widgets beforehand.
def handleSearches(self):
# do the search
browseThreads =
for idx, browser in enumerate(self.browsers):
browseThreads.append(BrowseThread(browser, self.data["options"][idx]))
for browseThread in browseThreads:
browseThread.start()
Where the browser as defined QWidget like following;
class Browser(QtWidgets.QWidget):
def __init__(self, title):
super().__init__()
self.gridLayout = QtWidgets.QGridLayout(self)
self.gridLayout.setObjectName("gridLayout")
self.webView = QWebEngineView()
self.webView.setUrl(QtCore.QUrl("https://www.google.com.tr"))
# some codes
def search(self, question, candidate, mode):
self.candidate = candidate
url = "https://www.google.com.tr/search?q={}".format(urllib.parse.quote_plus(candidate))
self.webView.setUrl(QtCore.QUrl(url))
def find_text(self, text):
soup = BS(self.src,'lxml')
# some source code alteration here
self.webView.page().setHtml(str(soup), self.webView.page().requestedUrl())
def on_page_load(self):
self.webView.page().toHtml(self.on_source_fetched)
def on_source_fetched(self, data):
self.src = data
self.find_text(self.candidate)
My Thread class is defined like following,
class BrowseThread (QThread):
def __init__(self, browser, searchString):
QThread.__init__(self)
self.searchString = searchString
self.browser = browser
def run(self):
self.search_text(self.searchString)
def search_text(self, text):
self.browser.search(text, '', 1)
What I am trying to achieve is to search different strings in parallel in 3 instances without blocking anything. Thread didn't work I guess because the browser widget GUI needs an update. How to do this?
Thanks.
python-3.x pyqt5 python-multithreading qthread qwebengineview
the GUI can not be executed in another thread, this is forbidden by Qt. Also multithreading is not parallelism, and instead of getting benefits you are getting problems
– eyllanesc
Jan 3 at 3:40
Do you have any heavy tasks that can block the GUI?
– eyllanesc
Jan 3 at 3:49
When I try to send search strings to "browsers" in for loop GUI is block for a few seconds and does some weird behavior. I need to finish this search in 3 window in 5 - 6 seconds. So the GUI should not freeze and page load should not wait for other "browsers". When the page loads I detect some html elements and change their html codes and reload the html source code into webview to see the detections.
– freezer
Jan 3 at 7:07
I think the task that brings you problems is # some codes, you could show an example where that problem will generate you, and I could give you a more precise example of the logic that prevents the window from freezing.
– eyllanesc
Jan 3 at 7:10
It is not that part cause the problem.That part only includes layout initialization. Problem rises when search function is executed for each browser. I tried Signal and Slot aproach. Seems working better but not good enough. Memory use is increases after each search and qtwebengine tasks stay openned in the task manager after I stop the compiler.. Causes pc to slow down.
– freezer
Jan 3 at 15:37
|
show 4 more comments
I have tried some suggestions on the net but couldn't succeed yet. Not sure if it is possible but will explain what I am trying to achieve.
I have a MainWindow which has the following method. And a button initializes three instances of browser widgets beforehand.
def handleSearches(self):
# do the search
browseThreads =
for idx, browser in enumerate(self.browsers):
browseThreads.append(BrowseThread(browser, self.data["options"][idx]))
for browseThread in browseThreads:
browseThread.start()
Where the browser as defined QWidget like following;
class Browser(QtWidgets.QWidget):
def __init__(self, title):
super().__init__()
self.gridLayout = QtWidgets.QGridLayout(self)
self.gridLayout.setObjectName("gridLayout")
self.webView = QWebEngineView()
self.webView.setUrl(QtCore.QUrl("https://www.google.com.tr"))
# some codes
def search(self, question, candidate, mode):
self.candidate = candidate
url = "https://www.google.com.tr/search?q={}".format(urllib.parse.quote_plus(candidate))
self.webView.setUrl(QtCore.QUrl(url))
def find_text(self, text):
soup = BS(self.src,'lxml')
# some source code alteration here
self.webView.page().setHtml(str(soup), self.webView.page().requestedUrl())
def on_page_load(self):
self.webView.page().toHtml(self.on_source_fetched)
def on_source_fetched(self, data):
self.src = data
self.find_text(self.candidate)
My Thread class is defined like following,
class BrowseThread (QThread):
def __init__(self, browser, searchString):
QThread.__init__(self)
self.searchString = searchString
self.browser = browser
def run(self):
self.search_text(self.searchString)
def search_text(self, text):
self.browser.search(text, '', 1)
What I am trying to achieve is to search different strings in parallel in 3 instances without blocking anything. Thread didn't work I guess because the browser widget GUI needs an update. How to do this?
Thanks.
python-3.x pyqt5 python-multithreading qthread qwebengineview
I have tried some suggestions on the net but couldn't succeed yet. Not sure if it is possible but will explain what I am trying to achieve.
I have a MainWindow which has the following method. And a button initializes three instances of browser widgets beforehand.
def handleSearches(self):
# do the search
browseThreads =
for idx, browser in enumerate(self.browsers):
browseThreads.append(BrowseThread(browser, self.data["options"][idx]))
for browseThread in browseThreads:
browseThread.start()
Where the browser as defined QWidget like following;
class Browser(QtWidgets.QWidget):
def __init__(self, title):
super().__init__()
self.gridLayout = QtWidgets.QGridLayout(self)
self.gridLayout.setObjectName("gridLayout")
self.webView = QWebEngineView()
self.webView.setUrl(QtCore.QUrl("https://www.google.com.tr"))
# some codes
def search(self, question, candidate, mode):
self.candidate = candidate
url = "https://www.google.com.tr/search?q={}".format(urllib.parse.quote_plus(candidate))
self.webView.setUrl(QtCore.QUrl(url))
def find_text(self, text):
soup = BS(self.src,'lxml')
# some source code alteration here
self.webView.page().setHtml(str(soup), self.webView.page().requestedUrl())
def on_page_load(self):
self.webView.page().toHtml(self.on_source_fetched)
def on_source_fetched(self, data):
self.src = data
self.find_text(self.candidate)
My Thread class is defined like following,
class BrowseThread (QThread):
def __init__(self, browser, searchString):
QThread.__init__(self)
self.searchString = searchString
self.browser = browser
def run(self):
self.search_text(self.searchString)
def search_text(self, text):
self.browser.search(text, '', 1)
What I am trying to achieve is to search different strings in parallel in 3 instances without blocking anything. Thread didn't work I guess because the browser widget GUI needs an update. How to do this?
Thanks.
python-3.x pyqt5 python-multithreading qthread qwebengineview
python-3.x pyqt5 python-multithreading qthread qwebengineview
edited Jan 4 at 10:12


Isma
8,57642238
8,57642238
asked Jan 2 at 21:19
freezerfreezer
1861925
1861925
the GUI can not be executed in another thread, this is forbidden by Qt. Also multithreading is not parallelism, and instead of getting benefits you are getting problems
– eyllanesc
Jan 3 at 3:40
Do you have any heavy tasks that can block the GUI?
– eyllanesc
Jan 3 at 3:49
When I try to send search strings to "browsers" in for loop GUI is block for a few seconds and does some weird behavior. I need to finish this search in 3 window in 5 - 6 seconds. So the GUI should not freeze and page load should not wait for other "browsers". When the page loads I detect some html elements and change their html codes and reload the html source code into webview to see the detections.
– freezer
Jan 3 at 7:07
I think the task that brings you problems is # some codes, you could show an example where that problem will generate you, and I could give you a more precise example of the logic that prevents the window from freezing.
– eyllanesc
Jan 3 at 7:10
It is not that part cause the problem.That part only includes layout initialization. Problem rises when search function is executed for each browser. I tried Signal and Slot aproach. Seems working better but not good enough. Memory use is increases after each search and qtwebengine tasks stay openned in the task manager after I stop the compiler.. Causes pc to slow down.
– freezer
Jan 3 at 15:37
|
show 4 more comments
the GUI can not be executed in another thread, this is forbidden by Qt. Also multithreading is not parallelism, and instead of getting benefits you are getting problems
– eyllanesc
Jan 3 at 3:40
Do you have any heavy tasks that can block the GUI?
– eyllanesc
Jan 3 at 3:49
When I try to send search strings to "browsers" in for loop GUI is block for a few seconds and does some weird behavior. I need to finish this search in 3 window in 5 - 6 seconds. So the GUI should not freeze and page load should not wait for other "browsers". When the page loads I detect some html elements and change their html codes and reload the html source code into webview to see the detections.
– freezer
Jan 3 at 7:07
I think the task that brings you problems is # some codes, you could show an example where that problem will generate you, and I could give you a more precise example of the logic that prevents the window from freezing.
– eyllanesc
Jan 3 at 7:10
It is not that part cause the problem.That part only includes layout initialization. Problem rises when search function is executed for each browser. I tried Signal and Slot aproach. Seems working better but not good enough. Memory use is increases after each search and qtwebengine tasks stay openned in the task manager after I stop the compiler.. Causes pc to slow down.
– freezer
Jan 3 at 15:37
the GUI can not be executed in another thread, this is forbidden by Qt. Also multithreading is not parallelism, and instead of getting benefits you are getting problems
– eyllanesc
Jan 3 at 3:40
the GUI can not be executed in another thread, this is forbidden by Qt. Also multithreading is not parallelism, and instead of getting benefits you are getting problems
– eyllanesc
Jan 3 at 3:40
Do you have any heavy tasks that can block the GUI?
– eyllanesc
Jan 3 at 3:49
Do you have any heavy tasks that can block the GUI?
– eyllanesc
Jan 3 at 3:49
When I try to send search strings to "browsers" in for loop GUI is block for a few seconds and does some weird behavior. I need to finish this search in 3 window in 5 - 6 seconds. So the GUI should not freeze and page load should not wait for other "browsers". When the page loads I detect some html elements and change their html codes and reload the html source code into webview to see the detections.
– freezer
Jan 3 at 7:07
When I try to send search strings to "browsers" in for loop GUI is block for a few seconds and does some weird behavior. I need to finish this search in 3 window in 5 - 6 seconds. So the GUI should not freeze and page load should not wait for other "browsers". When the page loads I detect some html elements and change their html codes and reload the html source code into webview to see the detections.
– freezer
Jan 3 at 7:07
I think the task that brings you problems is # some codes, you could show an example where that problem will generate you, and I could give you a more precise example of the logic that prevents the window from freezing.
– eyllanesc
Jan 3 at 7:10
I think the task that brings you problems is # some codes, you could show an example where that problem will generate you, and I could give you a more precise example of the logic that prevents the window from freezing.
– eyllanesc
Jan 3 at 7:10
It is not that part cause the problem.That part only includes layout initialization. Problem rises when search function is executed for each browser. I tried Signal and Slot aproach. Seems working better but not good enough. Memory use is increases after each search and qtwebengine tasks stay openned in the task manager after I stop the compiler.. Causes pc to slow down.
– freezer
Jan 3 at 15:37
It is not that part cause the problem.That part only includes layout initialization. Problem rises when search function is executed for each browser. I tried Signal and Slot aproach. Seems working better but not good enough. Memory use is increases after each search and qtwebengine tasks stay openned in the task manager after I stop the compiler.. Causes pc to slow down.
– freezer
Jan 3 at 15:37
|
show 4 more comments
0
active
oldest
votes
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54013325%2fpyqt5-handle-parallel-qwebengineview-page-loadings%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54013325%2fpyqt5-handle-parallel-qwebengineview-page-loadings%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
the GUI can not be executed in another thread, this is forbidden by Qt. Also multithreading is not parallelism, and instead of getting benefits you are getting problems
– eyllanesc
Jan 3 at 3:40
Do you have any heavy tasks that can block the GUI?
– eyllanesc
Jan 3 at 3:49
When I try to send search strings to "browsers" in for loop GUI is block for a few seconds and does some weird behavior. I need to finish this search in 3 window in 5 - 6 seconds. So the GUI should not freeze and page load should not wait for other "browsers". When the page loads I detect some html elements and change their html codes and reload the html source code into webview to see the detections.
– freezer
Jan 3 at 7:07
I think the task that brings you problems is # some codes, you could show an example where that problem will generate you, and I could give you a more precise example of the logic that prevents the window from freezing.
– eyllanesc
Jan 3 at 7:10
It is not that part cause the problem.That part only includes layout initialization. Problem rises when search function is executed for each browser. I tried Signal and Slot aproach. Seems working better but not good enough. Memory use is increases after each search and qtwebengine tasks stay openned in the task manager after I stop the compiler.. Causes pc to slow down.
– freezer
Jan 3 at 15:37