1.定时器
指定n秒后,执行任务
1 from threading import Timer,current_thread 2 import os 3 4 5 def hello(): 6 print("%s hello, world"%os.getpid()) 7 print("%s hello, world"%current_thread().name) 8 9 10 t = Timer(3, hello) 11 t.start() # after 1 seconds, "hello, world" will be printed 12 print(os.getpid()) 13 print(current_thread()) 14 15 # 12376 16 # <_MainThread(MainThread, started 12008)> 17 # 12376 hello, world 18 # Thread-1 hello, world