I'm trying to terminate python program if an input isn't provided by user within specific time frame, say - 5 seconds.
The code has been taken and edited from mediocrity's answer
import sys
import time
from threading import Thread
x = None
def check():
    global x
    time.sleep(5)
    if x:
        print("Input has been given!")
        return
    sys.exit()
Thread(target=check).start()
x = input("Input something: ")
But it keeps waiting for the input and doesn't terminate, unless the input is given. How could I change the code so that it executes as inteded?
 
     
    