If you want to restart the child thread after a specified time slice, you can use the class object provided by the standard library module threading Timer,
used to indicate the timer thread. Timer is a subclass of Thread, but also to start a thread by calling the method start ().
Threading the Timer Import from DEF do_sth (): ( '! the Hello the Timer') Print Timer after the Timer = (2, do_sth) # 2 seconds, performed do_sth timer.start ()
Timer is performed only once. If you need to execute once every so often, you need to call the child thread
creates internal function again and start the timer thread.
Threading the Timer Import from Import Time DEF do_sth (): Print ( '! the Hello the Timer') Global Timer Timer = the Timer (. 3, do_sth) # Cycle call, performed once every 3 seconds. timer.start () Timer = the Timer (2, do_sth) timer.start () the time.sleep (10) # parent thread 10 seconds delay timer.cancel () # cancel sub-thread