【问题标题】:In subprocess.Popen, which file does bufsize apply to?在subprocess.Popen中,bufsize适用于哪个文件?
【发布时间】:2011-04-09 09:41:00
【问题描述】:

我需要在Popen 对行缓冲的调用中设置stderr 流。我发现了 bufsize 参数,但它没有说明它实际应用于 3 个(stdinstdoutstderr)文件中的哪一个。

  • bufsize 参数是哪个文件 修改?
  • 如何修改另一个 文件缓冲模式?

【问题讨论】:

    标签: python stream subprocess popen buffering


    【解决方案1】:

    使用来源,卢克 :-) /usr/lib/python2.7/subprocess.py:

    if p2cwrite is not None:
        self.stdin = os.fdopen(p2cwrite, 'wb', bufsize)
    if c2pread is not None:
        if universal_newlines:
            self.stdout = os.fdopen(c2pread, 'rU', bufsize)
        else:
            self.stdout = os.fdopen(c2pread, 'rb', bufsize)
    if errread is not None:
        if universal_newlines:
            self.stderr = os.fdopen(errread, 'rU', bufsize)
        else:
            self.stderr = os.fdopen(errread, 'rb', bufsize)
    

    所以它似乎在所有这些中都使用了bufsize,无法具体说明。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-03-24
      • 2018-06-25
      • 2011-01-31
      • 2017-05-18
      • 2011-03-28
      • 2012-06-23
      • 1970-01-01
      相关资源
      最近更新 更多