用于线程的包装器。允许重置的计时器
resettabletimer的Python项目详细描述
resetTableTimer
为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