I've created a CLI little adventure game written in Python. I've defined a function that returns False whether time.sleep() is done and then I created a thread that allows the user to input the answer while self.is_time_elapsed() is True. Here's the code:
def if_time_elapsed(self,clock): time.sleep(clock) return False def main(self): while self.run: self.start_game() os.system('clear') print(Game.ascii_header) print(f'Welcome to this Adventure {self.usr_name}!') time.sleep(2) print('<START STORY>\nA terrible Iceberg destroyed the cruise ship you had taken enjoying the holidays,\n you ended up in the water at the mercy of the waves and you have to save yourself. ') print('\n<You\'ve got 10 seconds to write out the word "CLING" to cling to a rock.>') t_timer = threading.Thread(target=self.if_time_elapsed,args=(10,)) t_timer.start() while t_timer: usr_input = input('> ').lower().strip() if usr_input != 'cling': print("SCRRRR! Wrong answer!")The problem is that basically the program keeps asking the input without closing after timeout. I also tried with t_timer.run() insted of t_timer.start() but nothing.