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: long lines from interactive stdin are truncated
Type: behavior Stage: resolved
Components: Versions: Python 3.10, Python 3.9, Python 3.8
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: Anthony Sottile, ammar2, eryksun
Priority: normal Keywords:

Created on 2020-10-27 17:37 by Anthony Sottile, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (4)
msg379783 - (view) Author: Anthony Sottile (Anthony Sottile) * Date: 2020-10-27 17:37
this was originally pointed out in a comment on my youtube video here: https://youtu.be/Xf_82stIbB8


here's a reproduction:

1. produce 5000 characters of output: python3 -c 'print("a"*5000)'
2. copy that to the clipboard
3. run this: python3 -c 'import sys; print(len(sys.stdin.read()))'
4. paste
5. press enter
6. ^D

I get the following:

$ python3 -c 'import sys; print(len(sys.stdin.read()))'
...
4096

but I expect the value to be 5001 (+1 for the \n)
msg379786 - (view) Author: Ammar Askar (ammar2) * (Python committer) Date: 2020-10-27 17:44
This doesn't show up in piping so I think it might be a Linux terminal limitation. This thread claims a 4096 limit in cooked terminals, would you mind giving one of the work-arounds here a try and see if it that gets rid of it: https://unix.stackexchange.com/questions/131105/how-to-read-over-4k-input-without-new-lines-on-a-terminal
msg379788 - (view) Author: Anthony Sottile (Anthony Sottile) * Date: 2020-10-27 17:49
indeed! that's it -- you learn something every day :)
msg379789 - (view) Author: Eryk Sun (eryksun) * (Python triager) Date: 2020-10-27 18:47
For Windows see issue 41849. The legacy limit (i.e. PYTHONLEGACYWINDOWSSTDIO) for reading input via io.FileIO is 8K characters in Windows, but with io._WindowsConsoleIO, it's only 512 characters, which is far too small in general. The legacy implementation of input() based on C fgets() is capped at 4K characters in Windows, which is the same as a Linux terminal. The new implementation of input() in Windows (i.e. _PyOS_WindowsConsoleReadline) increases the limit to 16K characters. I'd like to see both cases increased to 32K characters, which is the length limit of a command line or file path in Windows.
History
Date User Action Args
2022-04-11 14:59:37adminsetgithub: 86341
2020-10-27 18:47:11eryksunsetnosy: + eryksun
messages: + msg379789
2020-10-27 17:49:11Anthony Sottilesetstatus: open -> closed
resolution: not a bug
messages: + msg379788

stage: resolved
2020-10-27 17:44:47ammar2setnosy: + ammar2
messages: + msg379786
2020-10-27 17:37:22Anthony Sottilecreate