How to simple run python3 thread in pyqt5 Qtimer
Dec 21, 2021
I wrote a python3 script with Qtimer but i got a hang or not response gui.
When my script is take long running my gui is hang.
I try to run Qtimer in thread but get error
QObject::startTimer: Timers can only be used with threads started with QThread
Then I try my trick
- create a thread
- add thread to function
- then run the function in Qtimer
Example
def start_thread(func, name=None, args = []):
threading.Thread(target=func, name=name, args=args).start()def check_process():
print(‘run check_process’)def run_thread():
start_thread(check_process)timer=QTimer()
timer.timeout.connect(run_thread)
timer.start(3000)
Hope this help, any error you can ask more on comment below