Reputation: 99
using PyQt5 as interface for my program, I wrote a function that is activated by clicking a button, and that function activates (among other things) another function that activates a thread that works on something else while the first function does its job. My problem is, that the function finishes much faster than the thread, and I want the program to wait for the thread to end before moving on, preferably with a timeout option. I know there are signals in PyQT5, and I know how to trigger events based on a signal given, however, how would I make the program wait for a signal to come?
Thank you very much for the help :)
example code of what I want:
class MyClass():
def __init__():
self.first_function()
....
....
def first_function(self):
....
....
self.second_function()
wait_for_signal(timeout=30)
def second_function(self):
....
t = threading.Thread(target=self.thread_func)
t.start()
....
....
def thread_func(self):
....
....
signal.emit()
Upvotes: 0
Views: 1057
Reputation: 46
I don't know exactly what do you need but here is an example of a function that in the start block signals and in the end activate them
def show_acte_general(self):
self.comboBox_2.blockSignals(True)
self.comboBox_2.clear()
self.comboBox_4.blockSignals(True)
self.comboBox_4.clear()
self.connection = psycopg2.connect(user="postgres", password="password", host="localhost", database="database")
self.cur = self.connection.cursor()
self.cur.execute('''SELECT items FROM read ORDER BY items ASC;''')
data = self.cur.fetchall()
for actes in data :
self.comboBox_2.addItem(actes[0])
self.comboBox_2.blockSignals(False)
self.comboBox_4.addItem(actes[0])
self.comboBox_4.blockSignals(False)
Upvotes: 0