【发布时间】: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