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 文件位于顶级分发目录中,以获取完整的许可证文本。

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

推荐PyPI第三方库


热门话题
java搜索按钮不适用于我   java制作一个应用程序来打开您自己的文件扩展名   XMemcached中的java异步集   java无法在Android上使用HTML5 canvas touch   java是否可以用PHP为Restlet创建客户端?   java在主题中添加图标。AppCompat。光   java Safari错误,无法打开浏览器   java gson解析json值中commaseparatedvalue字符串中的项   java如何使用Quarkus在卡夫卡的同一主题中设置多个使用者   java组织。json。JSONException:在{main}()的第6个字符处的main后面应该是“:”   windowbuilder如何将Java文件导出到GATE developer   java这与安卓 studio ide问题有关,在更新我们的ide之后   java Android将活动加载到类中<?>对象   java如何在springdatajpa中使用DISTINCT、GROUP BY和ORDER BY?   使用jlink的java可复制构建