Inputimeout doesn't wait for user input and immediately sends timeout message

def sneakyMinigame():
    global alert
    objective = None
    for i in range(15):
        objective = random.choice(string.ascii_letters)
        try:
            time_over = inputimeout(prompt = "Type "+objective+": ", timeout=2)
        except Exception:
            time_over="You trip and fall"
            print(time_over)
            alert = alert + 1
            break
        if response == objective:
            continue
        else:
            print("You made a noise! You are scared your mom will wake up, so you quickly head back to your room.")
            alert = alert + 1
            break

What is inputimeout?

Edit: I guess it’s this: GitHub - johejo/inputimeout: Multi platform standard input with timeout

Looks abandoned. May have succumbed to bit rot. What operating system and what Python version are you using?

You are catching Exception, which is typically a bad idea. It is too broad and may hide relevant tracebacks. You should do except TimeoutOccurred instead.

What may be happening is that inputimeout immediately raises an error other than TimeoutOccurred, which is caught by except Exception. That would result in the behavior you describe.

2 Likes

I am using Python 3.11.5 on Mac os

I think you’re not showing your complete code. There’s no inputimeout
in the standard library, so presumably it is imported from an additional
package, but there’s no such import in the code you showed.

at the top of my file i typed

from inputimeout import inputimeout, TimeoutOccured

What happens if you replace except Exception: with except TimeoutOccurred:?