kfira / python-multiprocessing

Automatically exported from code.google.com/p/python-multiprocessing
Other
0 stars 0 forks source link

subprocess redirection fails in child processes #16

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
The subprocess module in Python 2.5 can redirect the output of the executed
program to an internal buffer. Example:

import os,subprocess,multiprocessing

def f():
        p = subprocess.Popen(['echo', '-n', 'pss'], stdout=subprocess.PIPE)
        out = p.communicate()
        print(repr(out))
pr = multiprocessing.Process(target=f)
pr.start()

With python2.5, this outputs (None, None). python2.6 with native
multiprocessing yields the correct ('pss', None).

Workaround: Use one of the os.popen functions:

def f():
        streams = os.popen3('echo -n psss')
        out = (streams[1].read(), streams[2].read())
        print(repr(out))
pr = multiprocessing.Process(target=f)
pr.start()

yields ('psss, '') in python2.5 and python2.6.

Original issue reported on code.google.com by phihag.de@gmail.com on 27 Jun 2009 at 9:10

GoogleCodeExporter commented 8 years ago
See this issue, which will be fixed in python 2.7:

http://bugs.python.org/issue5313

I do not know when a backport is released, although I'd be glad to help.

Original comment by g2p.c...@gmail.com on 2 Jul 2009 at 1:36