每10秒运行一次Python脚本[关闭](Run Python script every 10 seconds [closed])

编程入门 行业动态 更新时间:2024-10-17 17:25:05
每10秒运行一次Python脚本[关闭](Run Python script every 10 seconds [closed])

我有一个功能来做一些工作。 代码应重复1.3亿次。

目前,我使用Crontab每1分钟运行一次python脚本。 它需要很长时间,我希望这个python脚本在第一次运行时运行,并在工作结束之前不断重复。 我想在2个任务之间休息10秒。 我怎样才能做到这一点?

I have a function to do some work. The code should repeat 130 million times.

Currently, I use Crontab to run a python script every 1 min. It takes too long a time, I want that this python script run when I run it the first time and keep repeating continuously until the work gets over. I want a 10 seconds break between 2 task. How can I do that?

最满意答案

尝试计划模块

import schedule import time def job(): print("I'm working...") schedule.every(10).minutes.do(job) schedule.every().hour.do(job) schedule.every().day.at("10:30").do(job) while 1: schedule.run_pending() time.sleep(1)

只需运行: pip install schedule

Try the schedule module

import schedule import time def job(): print("I'm working...") schedule.every(10).minutes.do(job) schedule.every().hour.do(job) schedule.every().day.at("10:30").do(job) while 1: schedule.run_pending() time.sleep(1)

Just run : pip install schedule

更多推荐

本文发布于:2023-08-01 12:29:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1358010.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:脚本   Python   Run   closed   seconds

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!