Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
input timer
@bowlofred im still having trouble with this i have been working on it for almost two weeks and still cant figure it out is there anyway you could pm me and help me work out the problem?
Sorry, I've not worked significantly with multithreaded items in python and have no special knowledge (was just making suggestions).

I'd suggest just continuing with updating the thread on things you've tried, what you expected of them, and what they did instead.
alright thank you
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)

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_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)
            print(prompt, end="", flush=True)
            result = input_queue.get(timeout=timeout)
            last_call_timed_out = False
            return result
        except queue.Empty:
            last_call_timed_out = True
            return None

    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

Possibly Related Threads…
Thread Author Replies Views Last Post
  email timer/rss feed timer ndiniz 1 730 Feb-02-2021, 07:18 PM
Last Post: nilamo
  input timer Nickd12 0 606 Nov-18-2020, 12:31 AM
Last Post: Nickd12

Forum Jump:

User Panel Messages

Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020