Python sys.stderr flush frequency

元气小坏坏 提交于 2019-12-05 05:43:09
jfs

On Python 2, I can't find where in the documentation sys.stderr's buffering is specified. I'd expect the same behaviour as stderr in C that is unbuffered (except Windows) and I don't know whether c99 standard mandates it. The standard error stream is not fully buffered in POSIX. -u option forces standard streams to be unbuffered in Python 2.

On Python 3:

When interactive, standard streams are line-buffered. Otherwise, they are block-buffered like regular text files. You can override this value with the -u command-line option.

-u command-line option:

Force the binary layer of the stdout and stderr streams (which is available as their buffer attribute) to be unbuffered. The text I/O layer will still be line-buffered if writing to the console, or block-buffered if redirected to a non-interactive file.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!