How to simple run python3 thread in pyqt5 Qtimer

Chuan Chudabut
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

  1. create a thread
  2. add thread to function
  3. 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

--

--