Tornado iLoop为人类提供的多线程/多进程任务调度程序驱动。
chronosp的Python项目详细描述
Chronos是由Tornado Ioloop驱动的多线程/多进程任务调度程序。
内容
Install
使用以下命令安装扩展:
$ easy_install chronospy
或者,如果安装了pip:
$ pip install chronospy
或者从github克隆它,然后在shell中运行命令:
cd chronos # the path to the project python setup.py install
Hello World
importtornadoimportchronosimportosimporturllib2deftest_process():print("process pid %s"%(os.getpid()))deftest(word):print("an other task, say '%s'"%(word))defsay():response=urllib2.urlopen('https://www.google.com/')html=response.read()print(html[:10])definit():# bind a ioloop or use default ioloopchronos.setup()# chronos.setup(tornado.ioloop.IOLoop())chronos.schedule('say',chronos.every_second(1),say)chronos.schedule('say2',chronos.every_second(1),test_process,once=True,process=True)chronos.schedule('say3',chronos.every_second(1),lambda:test("test3"))chronos.start(True)if__name__=='__main__':init()
API
schedule
计划(名称,计时器,func,once=false,start=false,process=false,max_executor=5)
将任务添加到Chronos:
name: | uniqe task name, |
---|---|
timer: | every timer object |
func: | the task function |
once: | set True will run only once time. |
start: | when chronos start and schedule a new task, if set to True will add to Tornado IOLoop and schedule to run at time. |
process: | if process is True, then the job will run in on a procees, otherwise defaultly running in thread. |
max_executor: | the max threads(or processes) to run a task. |
start
开始(start_ioloop=false)
在ioloop中添加任务,如果在tornado web服务器中使用chronos,则可以将start_ioloop设置为“false”,然后稍后启动自定义ioloop。
stop
停止(停止ioloop=false,清除=true)
停止ioloop中的任务
stop_ioloop: | will stop the ioloop if set to “True”. |
---|---|
clear: | will remove tasks from chrons if set to “True”. |
how to use every tools
every_at
设置每小时或每分钟运行一个作业:
every_at(hour=1, minute=10, second=0) # run at 01:10:00 every day every_at(minute=10, second=0) # run at run at 10 mintue every hour
every
every(10).minutesevery().hourevery().day.at("10:30")every().mondayevery().wednesday.at("13:15")
LICENSE
Copyright (C) 2015 Thomas Huang
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2 of the License.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.