Python subprocess.Popen在使用stdout = tempfile时不起作用

时间:2015-01-17 19:18:21

标签: python subprocess

我有Python脚本,使用 subprocess.Popen()运行一些测试而不会阻塞。

import datetime, os,subprocess, tempfile, time

tempfile.tempdir = None
tempFile = tempfile.TemporaryFile( bufsize=0 )
#args = ['ls'] # or whatever, to reproduce
process = subprocess.Popen( args, shell=False, bufsize=0, stdout=tempFile,
                            stderr=tempFile, preexec_fn=os.setsid, env=os.environ )


while process.poll() is None:
    time.sleep( 5 )
    now = datetime.datetime.now()

进程未返回任何错误。

如果我删除 stdout = tempFile ,则测试运行没有任何问题。

我正在使用Python 2.7.3

0 个答案:

没有答案