使用cron表达式的轻量级任务调度程序。
crython的Python项目详细描述
crython是一个轻量级的任务(函数)调度程序,使用 cron表达式写入 Python。
状态
此模块是主动维护的。
安装
从pip安装crython:
$ pip install crython
要从源安装Crython,请执行以下操作:
$ git clone git@github.com:ahawker/crython.git $ python setup.py install
用法
Crython支持七个字段(秒、分、小时、月日, 月、工作日、年)。
每分钟调用一次函数:
importcrython# Fire once a minute.@crython.job(second=0)deffoo():print"... while heavy sack beatings are up a shocking nine hundred percent? - Kent Brockman"
每隔10秒调用一个函数:
# Fire every 10 seconds.@crython.job(second=range(0,60,10))deffoo():print"I'm a big four-eyed lame-o and I wear the same stupid sweater every day. - Homer's Brain"
使用单个cron表达式调用函数:
# Fire every 10 seconds.@crython.job(second='*/10')deffoo():print"Hail to the thee Kamp Krusty... - Kampers"
使用完整的cron表达式调用函数:
# Fire once a week.@crython.job(expr='0 0 0 * * 0 *')deffoo():print"Back in line, maggot! - Kearny"
使用位置和/或关键字参数调用函数:
# Fire every second.@job('safety gloves',second='*',name='Homer Simpson')deffoo(item,name):print"Well, I don't need {0}, because I'm {1}. -- Grimey".format(item,name)调用函数
# Fire once a day.@crython.job(expr='@daily')deffoo():print"That's where I saw the leprechaun. He tells me to burn things! - Ralph Wiggum"
# Fire once immediately after scheduler starts.@crython.job(expr='@reboot')deffoo():print"I call the big one bitey. - Homer Simpson"
调用函数并在单独的线程中运行它(默认行为 如果未指定ctx:
# Fire once a week.@crython.job(expr='@weekly',ctx='thread')deffoo():print"No, no, dig up stupid. - Chief Wiggum"
调用函数并在单独的进程中运行它:
# Fire every hour.@crython.job(expr='@hourly',ctx='multiprocess')deffoo():print"Eat my shorts. - Bart Simpson"
启动全局作业计划程序:
if__name__=='__main__':crython.start()
关键词
Entry | Description | Equivalent To |
---|---|---|
@yearly/@annually | Run once a year at midnight in the morning of January 1 | 0 0 0 0 1 1 * |
@monthly | Run once a month at midnight in the morning of the first of the month | 0 0 0 0 1 * * |
@weekly | Run once a week at midnight in the morning of Sunday | 0 0 0 0 * 0 * |
@daily | Run once a day at midnight | 0 0 0 * * * * |
@hourly | Run once an hour at the beginning of the hour | 0 0 * * * * * |
@minutely | Run once a minute at the beginning of the minute | 0 * * * * * * |
@reboot | Run once at startup | @reboot |
待办事项
- 支持“L”、“W”和“”特价。
- 确定从现在开始的时间增量->;下一个时间表达式有效。
贡献
如果您想贡献,只需分叉存储库,推动 更改并发送请求。
许可证
Crython在MIT license下提供。
参见其他
有类似的python cron库。见: pycron, python-crontab, cronex