我正在寻找一种方法来设置时间限制,倒计时。我将使用此函数来控制用户可以运行 while 循环的时间量。这是一个如何运行的示例。
def run(strings, timeout=30):
while timeout > 0:
input = raw_input("prompts that will continue prompting as long as not timed out")
if input != strings:
#do something here, maybe be able to deduct off timer.
else:
score += 1
print "%d /r" % timeout #print timeout
return score
我的例子可能不是很简洁,但这是一般的想法。将timeout
控制循环。
timer
图书馆可以这样做吗?我是否需要一个单独的线程来处理我的函数运行时的时间(提示用户)?