Dec-08-2020, 01:55 AM
dose anyone know why i am getting this error when i let it timeout?
Fatal Python error: could not acquire lock for <_io.BufferedReader name='<stdin>'> at interpreter shutdown, possibly due to daemon threads
Python runtime state: finalizing (tstate=0000012F3B8CD730)
Fatal Python error: could not acquire lock for <_io.BufferedReader name='<stdin>'> at interpreter shutdown, possibly due to daemon threads
Python runtime state: finalizing (tstate=0000012F3B8CD730)
import queue import builtins import threading def make_input_function(): prompt_queue = queue.Queue(maxsize=1) input_queue = queue.Queue(maxsize=1) def getting_input(): while(prompt := prompt_queue.get()) != GeneratorExit: the_input = builtins.input(prompt) input_queue.put(the_input) prompt_queue.task_done() input_thread = threading.Thread(target=getting_input, daemon=True) last_call_timed_out = False def input_function(prompt=None, timeout=None): nonlocal last_call_timed_out if not last_call_timed_out: prompt_queue.put(prompt, block=False) else: print(prompt, end="", flush=True) try: result = input_queue.get(timeout=timeout) last_call_timed_out = False return result except queue.Empty: print(flush=True) last_call_timed_out = True return None input_thread.start() return input_function the_input = make_input_function() del make_input_function if (an_input := the_input("command: ", 4)) is not None: text = an_input print(text)