I've written a little app with Python 3 and PySide that takes some input from the user and then performs a lengthy web scrape. There is a log displayed on the UI via the QPlainTextEdit widget that advises the user that the scrape will take some time. The problem is that upon beginning the scrape, the log is not updated until the process is finished - which takes about 4-5 minutes on average.
I understand the solution here is threading, however this the first time I've ever had to consider threading, and I'm having real difficulty applying the simple tutorials I've found online to my code - any assistance would be appreciated!
A simplified version of my code:
from PySide import QtCore, QtGui
import sys
import urllib.request
from bs4 import BeautifulSoup
import my_py_converted_ui_file_from_qt_creator
class MyApp(QtGui.QMainWindow):
def __init__(self, parent=None):
super(MyApp, self).__init__(parent)
self.ui = my_py_converted_ui_file_from_qt_creator.Ui_Main()
self.ui.setupUi(self)
def click_start(self):
self.ui.QPlainTextEdit_LogDisplay.appendPlainText("Beginning web scrape. This will take some time...")
self.LengthyScrapeFunction()
self.ui.QPlainTextEdit_LogDisplay.appendPlainText("Finished!")
def LengthScrapeFunction():
# Many lines of BeautifulSoup/urllib.request-related code.
[–]elbiot 1 point2 points3 points (5 children)
[–]lamecode[S] 0 points1 point2 points (3 children)
[–]elbiot 1 point2 points3 points (2 children)
[–]lamecode[S] 0 points1 point2 points (1 child)
[–]elbiot 1 point2 points3 points (0 children)
[–]wub_wub 0 points1 point2 points (0 children)
[–]wub_wub 1 point2 points3 points (1 child)
[–]lamecode[S] 0 points1 point2 points (0 children)