locustio/locust · warning · InitError

Terminal says its a tty but we couldn't enable line input. K

Error message

Terminal says its a tty but we couldn't enable line input. Keyboard input disabled.

What it means

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.

Source

Thrown at locust/input_events.py:60

    def poll(_self):
        dr, dw, de = select.select([sys.stdin], [], [], 0)
        if not dr == []:
            return sys.stdin.read(1)
        return None


class WindowsKeyPoller:
    def __init__(self):
        if sys.stdin.isatty():
            try:
                self.read_handle = GetStdHandle(STD_INPUT_HANDLE)
                self.read_handle.SetConsoleMode(ENABLE_LINE_INPUT | ENABLE_ECHO_INPUT | ENABLE_PROCESSED_INPUT)
                self.cur_event_length = 0
                self.cur_keys_length = 0
                self.captured_chars = collections.deque()
            except pywintypes.error:
                raise InitError("Terminal says its a tty but we couldn't enable line input. Keyboard input disabled.")
        else:
            raise InitError("Terminal was not a tty. Keyboard input disabled")

    def cleanup(self):
        pass

    def poll(self):
        if self.captured_chars:
            return self.captured_chars.popleft()

        events_peek = self.read_handle.PeekConsoleInput(10000)

        if not events_peek:
            return None

        if not len(events_peek) == self.cur_event_length:
            for cur_event in events_peek[self.cur_event_length :]:
                if cur_event.EventType == KEY_EVENT:

View on GitHub (pinned to f391a716e1)

Solutions

  1. Run locust from a native Windows console (cmd/PowerShell/Windows Terminal) instead of an emulated pty
  2. Use `--headless` or the web UI without keyboard listener dependence
  3. Catch InitError around listener startup and continue without keyboard input

Example fix

// before
keyboard_listener = input_listeners.GKeyboardListener()  # raises InitError
// after
try:
    keyboard_listener = input_listeners.GKeyboardListener()
except InitError:
    keyboard_listener = None  # continue without keyboard input
Defensive patterns

Strategy: try-catch

Validate before calling

import sys
if sys.platform == "win32" and not sys.stdin.isatty():
    print("No console: keyboard input disabled")

Type guard

def windows_console_ok() -> bool:
    import sys
    return sys.platform != "win32" or sys.stdin.isatty()

Try / catch

from locust.input_events import InitError
try:
    listener = GKeyboardListener()
except InitError:
    listener = None  # degrade gracefully

Prevention

When it happens

Trigger: Running on Windows where GetStdHandle/SetConsoleMode fails despite isatty() being true — e.g. restricted console, redirected-in-part handles, or exotic terminal emulators.

Common situations: Running under IDE-consoles, MSYS/Cygwin pty shims, or scheduled tasks whose stdin handle does not support the legacy console mode APIs.

Related errors


AI-assisted analysis of locustio/locust@f391a716e1 (2026-08-29). Data as JSON: /api/errors/96b4aa0754ec3263. Report an issue: GitHub.