定时器
Thread 类有一个 Timer子类,该子类可用于控制指定函数在特定时间内执行一次。
import threading
def hello():
print("hello, world")
# 指定10秒后执行hello函数
t = Timer(10.0, hello)
t.start()
利用定时器循环运行函数,则在函数内部添加定时器即可
import threading
def hello():
print("hello, world")
t = Timer(10.0, hello)
t.start()
# 指定10秒后执行hello函数
t = Timer(10.0, hello)
t.start()
如何查看线程需要,可打印
print(threading.current_thread())