在multiprocessing.Process()中调用subprocess.Popen()时断管

时间:2010-10-02 00:08:33

标签: python subprocess multiprocessing

在multiprocessing.Process()中进行shell调用时遇到问题。错误似乎来自Git,但我无法弄清楚为什么它只发生在multiprocessing.Process()中。注意,下面是一个演示正在发生的事情的例子......在实际代码中,Process()中还有很多内容......但是我正在使用Popen来进行shell调用:

#!/usr/bin/python

import os
import shutil
from multiprocessing import Process
from subprocess 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()

结果是:

$ 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 个答案:

答案 0 :(得分:1)

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