作者:小美女金猪宝宝 | 来源:互联网 | 2022-12-08 15:42
我有一个功能,我需要在3天后使用python运行它
def hello()
print("hello world")
脚本将运行,如何在python中每3天打印一次
1> Green Cloak ..:
正如@Nuts在评论中所说,cron
如果你想每三天运行一个完整的程序,那么它是最好的选择.但是,如果您正在运行微服务或其他东西并且只想要每三天执行一个特定方法,则可以使用计时器.
import threading
my_timer = None
def make_thread():
# create timer to rerun this method in 3 days (in seconds)
global my_timer
my_timer = threading.Timer(259200, make_thread)
# call hello function
hello()
只需调用make_thread()
一次以执行hello()
第一次,然后它将每三天调用一次(几秒钟的错误余量,最有可能),只要程序保持运行.