Python sys.stderr刷新频率 [英] Python sys.stderr flush frequency

查看:156
本文介绍了Python sys.stderr刷新频率的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

sys.stderr多久刷新一次其缓冲区,并且此标准在不同环境中使用?

How often does sys.stderr flush its buffer, and is this standard among different environments?

>>> import sys
>>> sys.__stderr__
<open file '<stderr>', mode 'w' at 0x2b4fcb7ac270>

我看到它只是一种标准文件类型,但我不知道<应该是href = http://docs.python.org/2/library/functions.html#open rel = noreferrer> 缓冲 dir()似乎也没有产生任何有用的信息。

I see that it is just a standard file type, but I don't know what value of buffering it's supposed to be. dir() does not seem to yield any useful information either.

推荐答案

在Python 2上,我找不到文档 sys.stderr 的缓冲位置。我期望与 stderr 在无缓冲的情况下具有相同的行为 (Windows除外),我不知道c99是否标准要求它。 标准错误流未完全缓冲在POSIX中。 -u 选项强制在Python 2中取消缓冲标准流

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.

在Python 3上


互动时,标准流为-缓冲的。否则,它们
像常规文本文件一样被块缓冲。您可以使用 -u 命令行选项覆盖此
值。

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 命令行选项

-u command-line option:


强制将stdout和stderr流的二进制层(即
可作为其 buffer 属性使用)进行取消缓冲。如果写入控制台,则文本I / O
层仍将是行缓冲的,如果重定向到非交互式文件,则仍将
块缓冲。

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.

这篇关于Python sys.stderr刷新频率的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆