Eryk Sun <eryk...@gmail.com> added the comment:
> but I'm interrested in knowing more about the issue/original cause. When the readline module is imported in interactive mode, the PyOS_ReadlineFunctionPointer function pointer is set to call_readline(), which uses GNU Readline. Otherwise PyOS_Readline() calls PyOS_StdioReadline(), which calls my_fgets() and thus C standard I/O fgets(). In Linux, when the terminal is in canonical mode, a low-level read() is buffered with a limit of 4096 bytes. If the limit is exceeded, the call returns just the first 4095 bytes plus a trailing newline. You can verify this with os.read(0, 5000). GNU Readline disables canonical mode and works with the terminal at a lower level. I am far from an expert with Unix terminals, but here's the basics of something that allows input() to read more than 4096 characters without having to import the readline module. import sys import termios LFLAG = 3 settings = termios.tcgetattr(sys.stdin.fileno()) settings[LFLAG] &= ~termios.ICANON termios.tcsetattr(sys.stdin.fileno(), termios.TCSANOW, settings) try: s = input() finally: settings[LFLAG] |= termios.ICANON termios.tcsetattr(sys.stdin.fileno(), termios.TCSANOW, settings) print(len(s)) ---------- nosy: +eryksun _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue45511> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com