我正在尝试使用datetime
模块以类似于Linux中的crontab的方式工作。
目前在我的crontab中,我写的如下:
*/15 0-7 * * 1-6 python /user_data/my_code.py # Run every 15 mins between 12am-7am
*/5 8-17 * * 1-6 python /user_data/my_code.py # Run every 5 mins between 8am-5pm
*/10 18-20 * * 1-6 python /user_data/my_code.py # Run every 10 mins between 6pm-8pm
*/5 21-23 * * 1-6 python /user_data/my_code.py # Run every 5 mins between 9pm-11pm
我无法实现此crontab的原因是因为我在my_code.py中进行了一些更改而我不想 创建一些脚本以编写上面的crontab场景
EG。在my_code
def check_for_tasks(seconds):
...
# Run the following between 12am-7am if the task is more than 100 seconds
check_for_tasks(100)
# Run the following between 8am-5pm if the task is more than 80 seconds
check_for_tasks(80)
# Run the following between 6pm-8pm if the task is more than 50 seconds
check_for_tasks(50)
# Run the following between 9pm-11pm if the task is more than 150 seconds
check_for_tasks(150)
是否可以转换' crontab进入pythonic术语?
答案 0 :(得分:0)
您可以查看Schedule
人类的Python作业调度。
用于定期作业的进程内调度程序,它使用构建器模式进行配置。 Schedule允许您使用简单,人性化的语法以预定的时间间隔定期运行Python函数(或任何其他可调用的函数)。