2010-10-02 98 views
2

从multiprocessing.Process()中进行shell调用时出现问题。该错误似乎来自Git,但我无法弄清楚为什么它只发生在一个multiprocessing.Process()中。请注意,下面是一个示例来演示发生了什么......在实际代码中Process()中有更多内容正在进行......但我使用Popen将外壳调用作为其一部分:多处理程序中调用subprocess.Popen()时发生断管。()

#!/usr/bin/python 

import os 
import shutil 
from multiprocessing import Process 
from subprocess import Popen 

def run(): 
    cmd_args = ['git', 'clone', '[email protected]: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() 

结果是:

$ 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. 

任何帮助真的会很大......我还是新来的多模块和跨任何与它的问题还没有来,直到如今。

回答

1

Hrm,我刚刚意识到我在Python 2.6.1上运行....在2.6.4上运行同样的例子而不是有同样的问题。看起来像是在Python中修复的错误。

相关问题