【问题标题】:Broken Pipe when calling subprocess.Popen() within a multiprocessing.Process()在 multiprocessing.Process() 中调用 subprocess.Popen() 时管道损坏
【发布时间】:2010-10-02 00:08:32
【问题描述】:

我在从 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.

任何帮助都会非常棒...我还是多处理模块的新手,直到现在还没有遇到任何问题。

【问题讨论】:

    标签: python subprocess multiprocessing


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2016-10-05
      • 1970-01-01
      • 1970-01-01
      • 2017-01-31
      • 2010-10-28
      • 2011-03-19
      • 1970-01-01
      • 2012-05-15
      相关资源
      最近更新 更多