Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
input timer
#11
@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?
Reply
#12
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.
Reply
#13
alright thank you
Reply
#14
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_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)
Reply


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

Forum Jump:

User Panel Messages

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