python如何创建定时任务
1、首先安装schedule包:pip install schedule
2、在你的代码头部引用包:
import schedule
3、在你的代码中创建你的任务方法:
def Schedule():
# do something
4、在main方法中创建定时任务,如每分钟运行一次任务代码:
def main():
schedule.every().minutes.do(Schedule)
while True:
schedule.run_pending()
time.sleep(10)
5、运行你的代码:
python your_code.py
或者后台运行(Linux):
python your_code.py &
声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。
阅读量:49
阅读量:23
阅读量:195
阅读量:56
阅读量:22