使用threading.Timer实现非阻塞定时器 threading.Timer是一个在指定时间后执行一个操作的定时器,它不会阻塞主线程。 import threadingdef my_function():print("任务执行了!")print("定时器开始") timer = threading.Timer(5, my_function) # 5秒后执行my_function timer.start() # 启动定时器# 程序可以继续执行其他任务 print('hello')