您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

在Python中执行定期操作

在Python中执行定期操作

在的末尾foo(),创建一个在10秒后Timer调用foo()自身的。 因为,Timer创建一个新的thread要调用foo()。 你可以做其他事情而不会被阻止。

import time, threading
def foo():
    print(time.ctime())
    threading.Timer(10, foo).start()

foo()

#output:
#Thu Dec 22 14:46:08 2019
#Thu Dec 22 14:46:18 2019
#Thu Dec 22 14:46:28 2019
#Thu Dec 22 14:46:38 2019
python 2022/1/1 18:16:37 有564人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶