Timer2—Python函数的调度程序。
timer2的Python项目详细描述
Version: | 0.1.0 |
---|
简介
timer2模块允许您在特定时间调度python函数, 或者每隔一段时间。它可以用来代替threading.Timer, 区别在于timer2始终只使用单个线程(除非 您可以手动启动更多的程序)
你不应该用这个来进行昂贵的操作,因为这不会 在一个线程中运行时要有效,而应该使 计时器将操作移动到执行池(如线程/多处理 池,或发送消息):
>>> pool = multiprocessing.Pool() >>> timer2.apply_after(10000, pool.apply_async, (expensive_fun, ))
文档
Timer正在使用Sphinx,github上提供了最新的文档:
http://ask.github.com/timer2
安装
您可以通过python包索引(pypi)安装timer2。 或者来源。
使用pip,:
安装$ pip install timer2
使用easy_install,:
安装$ easy_install timer2
如果你下载了一个源tarball,你可以安装它 执行以下操作:
$ python setup.py build # python setup.py install # as root
示例
在nmsecs之后应用函数:
>>> import timer2 >>> timer2.apply_after(msecs, fun, args, kwargs, priority=0)
每隔nmsec应用函数:
>>> timer2.apply_interval(msecs, fun, args, kwargs, priority=0)
在特定日期应用函数(adatetime对象):
>>> timer2.apply_at(datetime, fun, args, kwargs, priority=0)
取消计时器
apply_*函数返回一个timer2.Entry实例, 您可以使用此命令取消执行:
>>> tref = timer2.apply_after(msecs, fun, args, kwargs) >>> tref.cancel()
运行自定义Timer线程
使用模块接口时,将启动默认计时器线程 一旦你安排好了什么。如果你想了解 手动线程,您可以使用timer2.Timer类:
>>> timer = timer2.Timer() >>> timer.apply_after(msecs, fun, args, kwargs) >>> timer.stop() # stops the thread and joins it.
缺陷跟踪器
如果您有任何建议、错误报告或烦恼,请报告 我们的问题跟踪者在http://github.com/ask/timer2/issues/
许可证
此软件是根据New BSD License授权的。参见LICENSE 文件位于顶级分发目录中,以获取完整的许可证文本。