{"id":1514,"library":"inputimeout","title":"Standard Input with Timeout","description":"inputimeout is a lightweight, cross-platform Python library that provides a standard input function with a specified timeout. It's useful for interactive scripts where user input is required within a limited timeframe. The current stable version is 1.0.4, with infrequent updates as it's a mature, focused utility.","status":"active","version":"1.0.4","language":"en","source_language":"en","source_url":"https://github.com/johejo/inputimeout","tags":["input","timeout","cli","utility","cross-platform"],"install":[{"cmd":"pip install inputimeout","lang":"bash","label":"Install stable version"}],"dependencies":[],"imports":[{"symbol":"inputimeout","correct":"from inputimeout import inputimeout"},{"symbol":"TimeoutOccurred","correct":"from inputimeout import TimeoutOccurred"}],"quickstart":{"code":"from inputimeout import inputimeout, TimeoutOccurred\n\ntry:\n    # Prompt for input with a 5-second timeout\n    user_input = inputimeout(prompt='Enter something within 5 seconds: ', timeout=5)\n    print(f\"You entered: {user_input}\")\nexcept TimeoutOccurred:\n    print(\"No input received within the time limit.\")\n    user_input = None\nexcept Exception as e:\n    print(f\"An error occurred: {e}\")","lang":"python","description":"This example demonstrates how to prompt a user for input with a 5-second timeout. If the user doesn't provide input within the specified time, a `TimeoutOccurred` exception is raised, which should be handled to prevent your program from crashing and to provide a fallback behavior."},"warnings":[{"fix":"Always wrap `inputimeout()` calls in a `try...except TimeoutOccurred` block to handle the case where no input is provided.","message":"Unlike the built-in `input()` function, `inputimeout()` raises a `TimeoutOccurred` exception if the timeout is reached. This exception *must* be explicitly caught.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Test your application's input behavior thoroughly in the target environment. Consider providing a fallback mechanism (e.g., using command-line arguments or environment variables) for non-interactive scenarios, or checking `sys.stdin.isatty()` before attempting timed input.","message":"The behavior of `inputimeout` can be inconsistent in non-interactive environments (e.g., some IDEs like PyCharm's run window, CI/CD pipelines, or certain terminal emulators) or when `sys.stdin` is redirected. It might immediately raise `TimeoutOccurred` or other I/O errors.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-09T00:00:00.000Z","next_check":"2026-07-08T00:00:00.000Z"}