【发布时间】:2021-01-22 04:44:27
【问题描述】:
我想构建一个在设定时间后停止另一个函数的函数。
例如:
def start():
global bol_start
bol_start = True
timer()
if bol_start is True:
"do something until time is over"
def stop():
global bol_start
bol_start = False
sys.exit(0)
def timer():
"code for actual timer" ?
我想让用户定义时间 x 工具应该运行 start() 多长时间。 时间结束后,它应该调用 stop()。
【问题讨论】:
-
这能回答你的问题吗? Timeout on a function call
-
嗯,无论如何,在这个例子中,你必须在
stop()中说global bol_start,不过我建议展示一个更好的例子
标签: python time timer process subprocess