I decided to add a graphical interface to one of my scripts. script is a simple scraper. I decided to use a workflow, as loading and analyzing data may take some time. I decided to use PySide, but my Qt knowledge is generally quite limited.
Since the script should wait for user input when captcha is intercepted, I decided that it should wait for QLineEdit
to start returnPressed
and then send it to the workflow so that it can send it for verification.This should be better than waiting for the click to wait return keys.
It seems that waiting for the signal is not as straightforward as I thought, and that would be, and after searching for some time I came across several solutions like this . The signaling by threads and the local loop of events in the work thread make my decision even more complex.
After he took a few hours, he still wonβt work.
What is going to happen:
- Download the data until you name captcha and enter the loop
- Download captcha and show it to user, run
QEventLoop
by calling self.loop.exec_()
- Exit
QEventLoop
by calling loop.quit()
on the workflow slot, which is connected via self.line_edit.returnPressed.connect(self.worker.stop_waiting)
in the main_window
class - Check the captcha and the loop if the check fails, otherwise repeat the last URL that should be downloaded now, then go to the next URL
What's happening:
... see above...
Exiting QEventLoop
does not work. self.loop.isRunning()
returns False
after calling its exit()
. self.isRunning
returns True
, so the thread does not seem to die under odd circumstances. However, the thread stops on the line self.loop.exec_()
. So the thread is stuck executing an event loop, although the event loop tells me that it no longer works.
The graphical interface responds in the same way as the slots of the workflow class. I see that the text is sent to the worker thread, the state of the event loop and the thread itself, but nothing happens after the above line is executed.
The code is a bit confusing, so I add a bit of pseudo-python-mix code, leaving it immaterial:
class MainWindow(...):
source share