Python定期执行某个方法不阻塞主线程
发布时间
阅读量:
阅读量
通过Timer实现带参数方法的调用过程
# 每隔10秒钟执行
import threading as thd
import time
# 真正要执行的函数
def fn(i):
print(time.time())
thd.Timer(10, fn,(i,)).start()
if __name__ == '__main__':
fn(1)
# 此处写你主线程要处理的事情.....
带多参
import threading as thd
import time
# 真正要执行的函数
def fn(i,str):
print(time.time())
print(str)
thd.Timer(10, fn,(i,str)).start()
if __name__ == '__main__':
fn(1,"hello")
全部评论 (0)
还没有任何评论哟~
