Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

subprocess redirection fails in child processes #16

Open
GoogleCodeExporter opened this issue Jan 23, 2016 · 1 comment
Open

subprocess redirection fails in child processes #16

GoogleCodeExporter opened this issue Jan 23, 2016 · 1 comment

Comments

@GoogleCodeExporter
Copy link

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
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant