gpt4 book ai didi

python - 在 multiprocessing.Process() 中调用 subprocess.Popen() 时管道损坏

转载 作者:太空宇宙 更新时间:2023-11-04 06:30:10 25 4
gpt4 key购买 nike

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

任何帮助都会很棒...我对多处理模块还是陌生的,直到现在才遇到任何问题。

最佳答案

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

关于python - 在 multiprocessing.Process() 中调用 subprocess.Popen() 时管道损坏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3843789/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com