This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: [Windows] stdin line buffer size
Type: enhancement Stage: resolved
Components: Windows Versions: Python 3.9
process
Status: closed Resolution: duplicate
Dependencies: Superseder: Support reading long lines with io._WindowsConsoleIO
View: 41849
Assigned To: Nosy List: Andrey Moiseev, eryksun, paul.moore, steve.dower, tim.golden, zach.ware
Priority: normal Keywords:

Created on 2021-04-08 09:33 by Andrey Moiseev, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (2)
msg390518 - (view) Author: Andrey Moiseev (Andrey Moiseev) Date: 2021-04-08 09:33
sys.stdin.readline() in Windows console only allows 512 characters on input per line. So large pastes are truncated at 512 chars, which is a bit inconvenient for prototyping.

The buffer size seems to be determined by BUFSIZ compile time constant:
https://github.com/python/cpython/blob/63298930fb531ba2bb4f23bc3b915dbf1e17e9e1/Modules/_io/winconsoleio.c#L30-L31

In C, I am able to set a larger buffer at runtime with setvbuf() call:
setvbuf(stdin, NULL, 0, 2024);

But I can't seem to make it work through ctypes.cdll.msvcrt.setvbuf
msg390520 - (view) Author: Eryk Sun (eryksun) * (Python triager) Date: 2021-04-08 09:46
The limit of 512 characters is not for sys.stdin in general. It's for io._WindowsConsoleIO, which gets used as the raw file for non-redirected sys.stdin -- and opening "CON" and "CONIN$" -- if legacy mode isn't enabled. See bpo-41849.
History
Date User Action Args
2022-04-11 14:59:44adminsetgithub: 87937
2021-04-08 09:46:46eryksunsetstatus: open -> closed

superseder: Support reading long lines with io._WindowsConsoleIO

nosy: + eryksun
messages: + msg390520
resolution: duplicate
stage: resolved
2021-04-08 09:33:51Andrey Moiseevcreate