小编use*_*ser的帖子

python-如何获取Timer中使用的函数的输出

我想运行10秒的功能,然后做其他的事情.这是我使用Timer的代码

from threading import Timer
import time

def timeout():
    b='true'
    return b

a='false'    
t = Timer(10,timeout)
t.start()

while(a=='false'):
    print '1'
    time.sleep(1)
print '2'
Run Code Online (Sandbox Code Playgroud)

我知道使用Timer I可以在定时器的末尾打印一些东西(打印b而不是返回b在10秒后返回true).我想知道的是:我可以在"a"中获取timeout()返回的值来正确执行我的while循环吗?

或者是否有另一种方法与另一个功能一起做?

python timer

5
推荐指数
1
解决办法
1583
查看次数

标签 统计

python ×1

timer ×1