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/

贡献

在github开发timer2http://github.com/ask/timer2

我们非常鼓励您参与开发。如果你不知道 像github(出于某种原因)一样,欢迎您发送常规补丁。

许可证

此软件是根据New BSD License授权的。参见LICENSE 文件位于顶级分发目录中,以获取完整的许可证文本。

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java楼梯的最大高度   java Jackson从1.7.1更新到2.8.6 JsonTypeInfo子类型反序列化   Spring WebApp中的java JPA异常处理   java在SwingWorker(doInBackground)中从WorkerThread调用多个方法?   java Android Studio构建到jar   java是添加多个按钮组的更有效方法   java MySQL JDBC连接池最大大小   java如何防止元素<Integer>变成元素<Object>   Java:处理大型XML文件提取数据而不编写状态自动机?   SpringBoot和React Web应用程序中CAS的java重定向问题   需要java算法方面的帮助吗   java在JDK 16中使用PowerMock   java异常错误本机方法签名   在Java Android中将JSON映射到数组/对象   如何打开一个窗口。java程序中的dat文件   java应用程序引擎+Maven+热插拔   java Moxy的getValueByXPath为除根元素以外的所有元素返回null