Popen().stdout.close()是否返回值? [英] Does Popen().stdout.close() return a value?

查看:133
本文介绍了Popen().stdout.close()是否返回值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我维护的代码中有

app7z = dirs['mopy'].join('7z.exe').s # path to 7z.exe
command = '"%s" a "%s" -y -r "%s\\*"' % (app7z, dstFile.temp.s, srcDir.s)
ins = Popen(command, stdout=PIPE, startupinfo=startupinfo).stdout
#--Error checking and progress feedback
reCompressing = re.compile('Compressing\s+(.+)')
regMatch = reCompressing.match
reError = re.compile('Error: (.*)')
regErrMatch = reError.match
errorLine = []
for line in ins:
    maCompressing = regMatch(line)
    if len(errorLine) or regErrMatch(line):
        errorLine.append(line)
    if maCompressing:
        # update progress
result = ins.close() # THIS
if result:
    dstFile.temp.remove()
    raise StateError(_("%s: Compression failed:\n%s") % (dstFile.s, 
                       "\n".join(errorLine)))

(完整代码)

ins.close()是否在失败时返回非None值?我的IDE(pycharm 3.4.2/4.5.2)警告我,它没有,但是并不一致.

Does ins.close() return a non None value on failure ? My IDE (pycharm 3.4.2/4.5.2) warns me that it does not, but then not consistently.

如果有帮助,我在Windows上-python 2.7.8

I am on windows if this makes a difference - python 2.7.8

推荐答案

您认为close可以返回什么? 您可能想使用wait获取退出代码:

What do you think, close can return? You probably want to use wait to get the exit code:

app7z = dirs['mopy'].join('7z.exe').s # path to 7z.exe
command = [app7z, 'a', dstFile.temp.s, "-y", "-r", os.path.join(src.Dir.s, '*')]
process = Popen(command, stdout=PIPE, startupinfo=startupinfo)
out = process.stdout
regMatch = re.compile('Compressing\s+(.+)').match
regErrMatch = re.compile('Error: (.*)').match
errorLine = []
for line in out:
    maCompressing = regMatch(line)
    if len(errorLine) or regErrMatch(line):
        errorLine.append(line)
    if maCompressing:
        # update progress
result = process.wait()
if result:
    dstFile.temp.remove()
    raise StateError(_("%s: Compression failed:\n%s") % (dstFile.s, 
                       "\n".join(errorLine)))

这篇关于Popen().stdout.close()是否返回值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆