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