{"record":{"id":"96b4aa0754ec3263","repo":"locustio/locust","slug":"terminal-says-its-a-tty-but-we-couldn-t-enable-lin","errorCode":null,"errorMessage":"Terminal says its a tty but we couldn't enable line input. Keyboard input disabled.","messagePattern":"Terminal says its a tty but we couldn't enable line input\\. Keyboard input disabled\\.","errorType":"exception","errorClass":"InitError","httpStatus":null,"severity":"warning","filePath":"locust/input_events.py","lineNumber":60,"sourceCode":"\n    def poll(_self):\n        dr, dw, de = select.select([sys.stdin], [], [], 0)\n        if not dr == []:\n            return sys.stdin.read(1)\n        return None\n\n\nclass WindowsKeyPoller:\n    def __init__(self):\n        if sys.stdin.isatty():\n            try:\n                self.read_handle = GetStdHandle(STD_INPUT_HANDLE)\n                self.read_handle.SetConsoleMode(ENABLE_LINE_INPUT | ENABLE_ECHO_INPUT | ENABLE_PROCESSED_INPUT)\n                self.cur_event_length = 0\n                self.cur_keys_length = 0\n                self.captured_chars = collections.deque()\n            except pywintypes.error:\n                raise InitError(\"Terminal says its a tty but we couldn't enable line input. Keyboard input disabled.\")\n        else:\n            raise InitError(\"Terminal was not a tty. Keyboard input disabled\")\n\n    def cleanup(self):\n        pass\n\n    def poll(self):\n        if self.captured_chars:\n            return self.captured_chars.popleft()\n\n        events_peek = self.read_handle.PeekConsoleInput(10000)\n\n        if not events_peek:\n            return None\n\n        if not len(events_peek) == self.cur_event_length:\n            for cur_event in events_peek[self.cur_event_length :]:\n                if cur_event.EventType == KEY_EVENT:","sourceCodeStart":42,"sourceCodeEnd":78,"githubUrl":"https://github.com/locustio/locust/blob/f391a716e12c2c712e80b5835e877b7933397453/locust/input_events.py#L42-L78","documentation":"On Windows, the keyboard listener sets the console mode to ENABLE_LINE_INPUT|ENABLE_ECHO_INPUT|ENABLE_PROCESSED_INPUT via SetConsoleMode. If the handle is a tty but the mode change fails (pywintypes.error), it raises InitError.","triggerScenarios":"Running on Windows where GetStdHandle/SetConsoleMode fails despite isatty() being true — e.g. restricted console, redirected-in-part handles, or exotic terminal emulators.","commonSituations":"Running under IDE-consoles, MSYS/Cygwin pty shims, or scheduled tasks whose stdin handle does not support the legacy console mode APIs.","solutions":["Run locust from a native Windows console (cmd/PowerShell/Windows Terminal) instead of an emulated pty","Use `--headless` or the web UI without keyboard listener dependence","Catch InitError around listener startup and continue without keyboard input"],"exampleFix":"// before\nkeyboard_listener = input_listeners.GKeyboardListener()  # raises InitError\n// after\ntry:\n    keyboard_listener = input_listeners.GKeyboardListener()\nexcept InitError:\n    keyboard_listener = None  # continue without keyboard input","handlingStrategy":"try-catch","validationCode":"import sys\nif sys.platform == \"win32\" and not sys.stdin.isatty():\n    print(\"No console: keyboard input disabled\")","typeGuard":"def windows_console_ok() -> bool:\n    import sys\n    return sys.platform != \"win32\" or sys.stdin.isatty()","tryCatchPattern":"from locust.input_events import InitError\ntry:\n    listener = GKeyboardListener()\nexcept InitError:\n    listener = None  # degrade gracefully","preventionTips":["Run from a native Windows console (cmd/PowerShell/Windows Terminal)","Avoid IDE pty shims for interactive locust runs","Use --headless when no console is available"],"tags":["windows","terminal","console","input"],"backgroundTag":"not-a-tty","analyzedSha":"f391a716e12c2c712e80b5835e877b7933397453","analyzedAt":"2026-08-29T00:36:13.872Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}