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

2024-09-29 22:31:39 发布

您现在位置:Python中文网/ 问答频道 /正文

我使用python的stdin从其他进程接收消息

但是想改变快速接收消息的stdin buff大小吗

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

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

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

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

我的主机是一台linux机器。。在


Tags: 机器消息进程linuxstdinbuffstdinbuff
1条回答
网友
1楼 · 发布于 2024-09-29 22:31:39

来自an answer to a similar question

You can completely remove buffering from stdin/stdout by using python's -u flag:

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

and the man page clarifies:

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

除此之外,它还没有得到(良好的或广泛的)支持。在

相关问题 更多 >

    热门问题