I'm trying to run a background timer while running other processes. I've used thread.Thread:
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()
That`s all my code. The problem is that when i run it, the timer waits for input before exiting. I want the timer to exit at ten second mark, whether or not input was entered. I thought that threading would make it so that the processes would not have to wait for each other. Help please? Oh, and I'm only a few days into python, so please keep your explanations simple. Thanks.