两种方式
1、自己写一个函数
#!/usr/local/python3/bin/python32、使用schedule库
import time
def timed_execution(interval, function, *args, **kwargs):
while True:
function(*args, **kwargs)
time.sleep(interval)
def say_hello():
print("Hello World!/n")
timed_execution(5, say_hello)
#!/usr/local/python3/bin/python3
# -*- coding: utf-8 -*
import schedule
import time
def job():
print("I'm running..")
# 每隔10秒钟执行一次job函数
schedule.every(10).seconds.do
#schedule.every().hour.at("10:00").do(job)#每天10点执行
while True:
schedule.run_pending()
time.sleep(1)
网友回复