Answer the question
In order to leave comments, you need to log in
Why does PyQt5 application window freeze?
for link in self.all_links:
tr = threading.Thread(target=self.sucess_send_request, args=(link, valid_proxy))
tr.start()
tr.join()
Answer the question
In order to leave comments, you need to log in
Because join() stops the thread of execution - in your case the GUI thread that is responsible for running the application window - until the target thread is finished. Those. what you are doing is the equivalent of just calling self.sucess_send_request(link, valid_proxy) right in the event handler.
Should I wait until when? By the time the window closes? Or to what?
I would do this: make global objects (like class fields) available to all threads. One is of type threading.Lock, one is a counter, and one is of type threading.Event().
When the thread starts, it grabs the Lock, increments the counter and resets the Event (the clear() method), releases the Lock.
When the thread is ready to terminate, it captures the Lock and decrements the counter. If, after decrementing, the counter becomes equal to 0, sets the Event (set() method). Then releases Lock. Make sure this happens inside try: finally: so that an uncaught exception doesn't break the system.
Then the main thread of the application can simply check the current value of the counter (number of active threads) from time to time. And if necessary, it can wait on the Event object to wait for all threads to complete.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question