I am trying to make a timer that runs concurrently with a key-listener. The key-listener should perform a function when it takes a key and stop the timer. Below is the code I wrote. Though when I run it, the timer runs infinitely but the the key-listener does not listen for keys thus not print what it's supposed to.
Nota bene I am just getting into threading so the whole code I have written may be logically wrong in the paradigm of threading.
import concurrent.futures
import time
import os
import keyboard
run_timer = True
keep_scanning = True
def startTimer(seconds):
while run_timer:
for i in range(1, seconds):
print(i)
time.sleep(1)
os.system("clear")
def scanForInput():
while keep_scanning:
print(keep_scanning)
if keyboard.is_pressed('space'):
keep_scanning = False
run_timer = False
return "HIT"
with concurrent.futures.ThreadPoolExecutor() as executor:
f1 = executor.submit(startTimer, 4)
f2 = executor.submit(scanForInput)