Python timing in order to trigger specific events

强颜欢笑 提交于 2019-12-06 15:45:06

time.time() returns second since epoch as a floating point number like:

>>> import time
>>> time.time()
1465572505.891256

If your comparison:

time.time()-start) == times[0]

to time.time() isn't correct down to the microsecond (this depends on the system), then the == won't be True and you'll never get your triggeredAction().

Do things by the second if that works for you, use: int(time.time()) and do the same for your uniform_min_range return values - assuming per second resolution is ok for you. Otherwise you'll need to introduce a range (+ or - 1s) to your triggered action check.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!