跳转到主要内容

timer2 - Python函数的调度器。

项目描述

版本::
0.1.0

简介

timer2模块让您可以在特定时间或间隔调度Python函数。它可以作为threading.Timer的替代品,区别在于timer2始终只使用一个线程(除非您手动启动更多线程)

您不应使用此来执行昂贵的操作,因为这不会在单线程运行时有效,相反,您应该让定时器将操作移动到执行池(如线程/多进程池,或者可能发送消息)

>>> pool = multiprocessing.Pool()
>>> timer2.apply_after(10000, pool.apply_async, (expensive_fun, ))

文档

定时器使用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

示例

n毫秒后应用函数

>>> import timer2
>>> timer2.apply_after(msecs, fun, args, kwargs, priority=0)

每隔n毫秒应用函数

>>> timer2.apply_interval(msecs, fun, args, kwargs, priority=0)

在特定日期(datetime对象)应用函数

>>> 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/向我们报告。

贡献

timer2 的发展在 Github 上进行:http://github.com/ask/timer2

我们鼓励您参与开发。如果您不喜欢 Github(出于某种原因),您也可以发送常规补丁。

许可证

本软件采用 New BSD License 许可。有关完整许可文本,请参阅顶级分发目录中的 LICENSE 文件。

项目详情


下载文件

下载您平台上的文件。如果您不确定选择哪个,请了解更多关于 安装包 的信息。

源代码分发

timer2-0.1.0.tar.gz (126.0 kB 查看哈希值)

上传时间 源代码