Jython subprocess.Popen不保存对stdout参数

时间:2016-04-01 02:47:07

标签: python jython

Jython 2.7.0的subprocess.Popen实现似乎没有对stdout传入的句柄的引用,这与CPython 2.7.10的行为形成对比。这是一个Jython错误还是符合Python实现,允许在这些情况下垃圾收集文件句柄fh

例如,

import subprocess

perl_loop = """
$c = 0;
while (1) {
     print "$c\n";
     $c++;
}
"""

def func():  
    fh = open('./counter.out', 'a')
    process_handle = subprocess.Popen(
            ["perl", "-e", perl_loop],
            stdout=fh)
    return process_handle

func().wait()
一段时间后,

在stderr上产生以下输出

Exception in thread "_CouplerThread-2 (stdout)" Traceback (most recent call last):
   File "<home-directory>/bin/jython-standalone-2.7.0.jar/Lib/subprocess.py", line 754, in run
IOError: java.nio.channels.ClosedChannelException

0 个答案:

没有答案