【问题标题】:how to change the python's stdin buffer size? [duplicate]如何更改 python 的标准输入缓冲区大小? [复制]
【发布时间】:2015-10-16 20:20:06
【问题描述】:

我使用 python 的标准输入来接收来自其他进程的消息

但想更改快速接收消息的标准输入缓冲区大小

我知道子进程可以在打开子进程时设置stdin buff

但是我的一个进程是一个发送消息的 c 进程

另一个是接收消息的python进程

如何在 python 中更改标准输入缓冲区大小?

我的主机是一台linux机器..

【问题讨论】:

  • 那是一首美丽的诗。
  • @jdi 谢谢你的笑声!

标签: python linux stdin


【解决方案1】:

来自an answer to a similar question

您可以使用 python 的 -u 标志从标准输入/标准输出中完全删除缓冲:

-u     : unbuffered binary stdout and stderr (also PYTHONUNBUFFERED=x)
         see man page for details on internal buffering relating to '-u'

手册页说明:

  -u     Force stdin, stdout and stderr to  be  totally  unbuffered.   On
         systems  where  it matters, also put stdin, stdout and stderr in
         binary mode.  Note that there is internal  buffering  in  xread-
         lines(),  readlines()  and  file-object  iterators ("for line in
         sys.stdin") which is not influenced by  this  option.   To  work
         around  this, you will want to use "sys.stdin.readline()" inside
         a "while 1:" loop.

除此之外,它不受(很好或广泛)支持。

【讨论】:

  • 如果您只是抄袭另一个答案,正确的做法是将问题标记为重复。
  • 抱歉,我找不到这样做的按钮。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2023-04-08
  • 2018-12-12
  • 1970-01-01
  • 2015-10-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多