【发布时间】:2017-02-09 22:31:08
【问题描述】:
如果我使用subprocess.Popen,我可以使用communicate() 进行小输出。
但如果子流程要花费大量时间并产生大量输出,我想将其作为流数据访问。
有没有办法做到这一点? Python 文档说
警告:使用
communicate()而不是.stdin.write、.stdout.read或.stderr.read以避免由于任何其他操作系统管道缓冲区填满并阻塞子进程而导致的死锁。
我真的很想以类似文件的对象的形式访问进程输出:
with someMagicFunction(['path/to/some/command','arg1','arg2','arg3']) as outpipe:
# pass outpipe into some other function that takes a file-like object
但不知道该怎么做。
【问题讨论】:
标签: python io subprocess