用于线程的包装器。允许重置的计时器

resettabletimer的Python项目详细描述


resetTableTimer

Build Status

threading.Timer提供可重置计时器实现的包装器。还为测试提供假计时器。

用法

resetTableTimer

# If using python 2, import print functionfrom__future__importprint_functionfromresettabletimerimportResettableTimerdelay=5# secondsfunction=print# Create resettable timert=ResettableTimer(delay,function,["Hello"],{"end":" timer!\n"})# Starting and canceling work similarly than with threading.Timert.start()# Wait 1-5 seconds# Reset the timert.reset()# Hello should be printed after five seconds

faketimer

# If using python 2, import print functionfrom__future__importprint_functionfromresettabletimerimportFakeTimert=FakeTimer(2,print,["Hello"],{"end":" timer!\n"})# Starting and canceling work similarly than with threading.Timert.start()# Wait >2 seconds# Nothing happens# Time passage is controlled with pass_timet.pass_time(2)# Hello should be printed

测试

使用命令运行单元测试:

cd resettabletimer

python3 -m unittest discover -s tst/

使用命令获取测试覆盖率:

cd resettabletimer

coverage run -m unittest discover -s tst/
coverage report -m

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

推荐PyPI第三方库


热门话题
java如何在不影响项目中其他jtabbed窗格的情况下更改jtabbed窗格所选选项卡的颜色   java域模型映射器应该是静态的吗?   java使用javamail api在outllok中打开包含电子邮件作为附件的附加电子邮件   java Swagger扩展SwaggerSpecFilter   Java泛型数组类强制转换异常   java如何使用opencv计算人脸识别的百分比格式预测置信度?   jakarta ee Java ee:如何从web模块访问本地EJB?   java如何将变量传递到同一个包中的另一个类中   通过FTP在Java中上传文件   java似乎无法在JFrame中更新我的GridLayout。现在它增加了越来越多的帧,我只想更新它   java我的代码中有什么可以识别为病毒?   java在Android Studio中添加延迟计时器   javascript值更改事件并单击事件   java如何优雅地处理更新版本中的数据库升级?   java如何在Intellij Idea中切换到其他git帐户   无效的Java正则表达式   java使用相同的方法向字符串或其他对象的ArrayList添加元素   使用数组作为参数的java   java ASM拦截在方法外部进行的字段访问