他のプロセスを実行している間にバックグラウンドタイマーを実行しようとしています。私はスレッドを使用しました。スレッド:スレッディングプロセスの入力待ち
import threading
import random
import time
import sys
def timer(limit):
time.sleep(limit)
sys.exit()
def code():
dictionary=['hello','loading','dumb']
word=[]
c=random.choice(dictionary)
answer=c
for x in c:
word.append(x)
y=0
words=''
while y!=len(c):
x=random.choice(word)
word.remove(x)
words=words+x
y+=1
print(words)
guess=input()
if guess==answer:
print('NOICE')
else:
print("NUB")
permit=input('Play Again?')
t1=threading.Thread(target=timer, args=(10,))
t2=threading.Thread(target=code)
t1.start()
t2.start()
これはすべて私のコードです。問題は、私がそれを実行すると、タイマーが終了する前に入力を待つことです。私は、タイマーが入力されたかどうかに関わらず、10秒目に終了するようにします。私はスレッディングがプロセスをお互いに待つ必要がないようにすると思った。助けてください? ああ、私は数日しかないので、あなたの説明を簡単にしてください。ありがとう。
Windowsを使用していない場合は、いくつかの有益な回答があります。[こちら](http://stackoverflow.com/questions/1335507/keyboard-input-with-timeout-in-python) – John