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?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
It depends on how you use subprocess
:
subprocess.call("some-program")
will block until some-program
completes.
p = subprocess.Popen("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")
is basically the same as
output, stderr = subprocess.Popen("some-program").communicate()