子流程调用,它们是并行完成的吗? [英] Subprocess calls, are they done in parallel?

查看:87
本文介绍了子流程调用,它们是并行完成的吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在谷歌搜索这个问题的答案,但似乎没有一个答案.谁能告诉我subprocess模块是否并行执行其调用? Python文档建议它可用于产生新进程,但未提及它们是否并行.如果可以并行完成,可以请给我一个例子或将我链接到一个例子吗?

I've been Googling for an answer to this question but nowhere seems to have one. Can anyone tell me if the subprocess module does its calls in parallel? The Python docs suggest it can be used to spawn new processes, but it doesn't mention if they are in parallel or not. If they can be done in parallel could you kindly show me an example or link me to one?

推荐答案

这取决于您使用subprocess的方式:

It depends on how you use subprocess:

subprocess.call("some-program")

将阻塞,直到some-program完成.

p = subprocess.Popen("some-program")

将在单独的进程中运行some-program,与脚本的其余部分并行.

will run some-program in a separate process, in parallel with the remainder of your script.

请注意,第一个只是一个方便的包装器,等效于

Note that the first is simply a convenient wrapper that is equivalent to

subprocess.Popen("some-program").wait()    

output = subprocess.check_output("some-program")基本上与

output, stderr = subprocess.Popen("some-program").communicate()

这篇关于子流程调用,它们是并行完成的吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆