Python定时器倒计时
我想了解Python中的定时器。
假设我有一个类似以下的代码片段:
def abc()
print 'Hi'
print 'Hello'
print 'Hai'
我想每 1 秒打印一次。最多三次;即;第一秒我需要检查 printf,第二秒我也需要在第三秒检查。
在我的实际代码中,变量值将被更新。 我需要捕获所有变量在哪一秒更新。
谁能告诉我该怎么做。
I want to know about timer in Python.
Suppose i have a code snippet something like:
def abc()
print 'Hi'
print 'Hello'
print 'Hai'
And i want to print it every 1 second. Max three times;ie; 1st second i need to check the printf, 2nd second I need to check as well in 3rd second.
In my actual code variables value will be updated.
I need to capture at what second all the variables are getting updated.
Can anybody tell me how to do this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
time.sleep
在这种情况下没问题,但是如果abc()
函数需要半秒才能执行怎么办?还是5分钟?在这种情况下,您应该使用
Timer
对象。time.sleep
is fine in this case but what if theabc()
function takes half a second to execute? Or 5 minutes?In this case you should use a
Timer
object.使用
time.sleep
。Use
time.sleep
.您应该查看
time.sleep()
。例如:这将打印您的行 5 次,中间有 3 秒的延迟。
You should look into
time.sleep()
. For example:That will print your lines 5 times with a 3 second delay between.
通常对我来说这有效......
我想你可以猜到......
usually for me this works...
I think you can guess after that...