時間制限、カウントダウンを設定する方法を探しています。この関数を使用して、ユーザーが 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
これはライブラリに対して実行できますか? 関数の実行中 (ユーザーにプロンプトを表示) に時間を処理するために別のスレッドが必要ですか?