开发者

Broken Pipe when calling subprocess.Popen() within a multiprocessing.Process()

I am having an issue when making a shell call from within a multiprocessing.Process(). The error seems to be coming from Git, but I just can't figure out why it only happens from within a multiprocessing.Process(). Note, below is an example to demonstrate what's happening... in real code there is a lot more going on within the Process()... but I'm using Popen to make shell calls as part of it:

#!/usr/bin/python

import os
import shutil
from multiprocessing import Process
from subprocess开发者_如何学Python import Popen

def run():
    cmd_args = ['git', 'clone', 'git@github.com:derks/test.git', 'test-repo-checkout']
    res = Popen(cmd_args)
    res.wait()

# clean
if os.path.exists('./test-repo-checkout'):
    shutil.rmtree('./test-repo-checkout')

print "\n--- this doesnt work"
process = Process(target=run)
process.start()
process.join()

print "\n--- this does work"
run()

The result is:

$ python test.py

--- this doesnt work
Cloning into test-repo-checkout...
Warning: untrusted X11 forwarding setup failed: xauth key data not generated
Warning: No xauth data; using fake authentication data for X11 forwarding.
fatal: write error: Broken pipe

--- this does work
Cloning into test-repo-checkout...
Warning: untrusted X11 forwarding setup failed: xauth key data not generated
Warning: No xauth data; using fake authentication data for X11 forwarding.
remote: Counting objects: 9, done.
remote: Compressing objects: 100% (5/5), done.
remote: Total 9 (delta 1), reused 0 (delta 0)
Receiving objects: 100% (9/9), done.
Resolving deltas: 100% (1/1), done.

Any help would really be great... I'm still new to the multiprocessing module and haven't come across any issues with it until now.


Hrm, I just realized I was running on Python 2.6.1 .... running the same example on 2.6.4 does not have the same issue. Looks like a bug that was fix in Python.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜