gpt4 book ai didi

javascript - 是否可以在Python中创建一个类似于JS间隔的函数?

转载 作者:太空宇宙 更新时间:2023-11-03 20:14:11 25 4
gpt4 key购买 nike

是否可以像在 JS 中使用 setTimer 那样在 Python 中以预定义的时间间隔异步执行代码?

例如,Python 中的函数 example() 每 60 秒就会调用一次。我怎样才能做到这一点?

最佳答案

import threading

def printit():
threading.Timer(5.0, printit).start()
print "Hello, World!"

printit()

答案来自:Run certain code every n seconds

关于javascript - 是否可以在Python中创建一个类似于JS间隔的函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58564308/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com