4

I want run some timer in thread,but it display ERRORTypeError: start() argument after * must be an iterable, not int,How can I fix it?

    while 1:
            try:
                _thread.start_new_thread(self.timer0.start,100)
                _thread.start_new_thread(self.timer1.start,150)
                _thread.start_new_thread(self.timer2.start,200)
                _thread.start_new_thread(self.timer3.start,250)
                _thread.start_new_thread(self.timer4.start,300)
                break
            except:
                print ("Error: unable to start thread")
            break
kevin880701
  • 85
  • 1
  • 2
  • 10

1 Answers1

13

Check the docs: https://docs.python.org/3/library/_thread.html

_thread.start_new_thread(function, args[, kwargs])

Start a new thread and return its identifier. The thread executes the function function with the argument list args (which must be a tuple).

Thus, the correct call looks like:

_thread.start_new_thread(self.timer0.start, (100,))
Community
  • 1
  • 1
Lesiak
  • 22,088
  • 2
  • 41
  • 65
  • It say 'QObject::startTimer: Timers cannot be started from another thread' – kevin880701 Jun 11 '19 at 14:10
  • 2
    It seems that you are obsessed with threading, and you want to use it at all times, the QTimer is a QObject that is not thread-safe so you can not modify it from another thread, that's why Qt tells you not to modify the QTimer from a thread different from the what was created – eyllanesc Jun 11 '19 at 14:13