Repository navigation
gh-158414: Fix hang when writing incomplete UTF-8 sequence to Windows console - #158435
Conversation
cmaloney
left a comment
There was a problem hiding this comment.
This is likely going to cause gh-110913 in some cases. I think in explicit flush always emptying the buffer fully is good; partial emoji printing is okay in that case.
I worry with this being in the write loop regardless of "is this a flush" is going to result in more broken than good. Emptying most but not all here I think would be nice (Although that may have implications for buffering layers above this).
|
Thank you for the review! Other paths not in Also, the fallback in this change only triggers in cases that currently hang, so it won’t make the normal path worse. I think it’s better not to make it too complex. |
|
GH-162168 is a backport of this pull request to the 3.15 branch. |
|
GH-162169 is a backport of this pull request to the 3.14 branch. |
After gh-124008,
_find_last_utf8_boundary()may return 0 when the data is only an incomplete UTF-8 sequence, which causesflush()to hang.In this case, use the original
leninstead, so the data is written as "�". I don't think there is a better way to handle it correctly without adding too much complexity.sys.stdout.buffer.flush()hangs forever on incomplete UTF-8 bytes #158414