如何更改python的stdin缓冲区大小?

时间:2012-12-27 06:31:17

标签: python linux stdin

我使用python的stdin来收集来自其他进程的消息

但想要更改快速recv消息的stdin buff大小

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

但我的一个过程就是发送消息的过程

另一个是recva消息的python进程

如何更改python中的stdin buff大小?

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

1 个答案:

答案 0 :(得分:0)

来自an answer to a similar question

  

您可以使用python' s -u标志从stdin / stdout中完全删除缓冲:

-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.

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