<p>问题是<code>os.system</code>在程序完成之前不会返回,<code>ssh</code>直到您给它的命令完成后才会返回。在</p>
<p>这是不使用<code>os.system</code>-正如<a href="http://docs.python.org/2/library/os.html#os.system" rel="nofollow">the documentation</a>明确指出的那样:</p>
<blockquote>
<p>The subprocess module provides more powerful facilities for spawning new processes and retrieving their results; using that module is preferable to using this function. See the Replacing Older Functions with the subprocess Module section in the subprocess documentation for some helpful recipes.</p>
</blockquote>
<p>在<code>subprocess</code>中,您可以创建一组子流程,然后在所有子流程启动后将它们全部合并。例如:</p>
<pre><code>p1 = subprocess.Popen("ssh igp@" + str(comp1[0]) + " blender -b "+ str(path) +" -s " + str(comp1[1]) + " -e " + str(comp1[2]) + " -a", shell=True)
p2 = subprocess.Popen("ssh igp@" + str(comp2[0]) + " blender -b "+ str(path) +" -s " + str(comp2[1]) + " -e " + str(comp2[2]) + " -a", shell=True)
p3 = subprocess.Popen("ssh igp@" + str(comp3[0]) + " blender -b "+ str(path) +" -s " + str(comp3[1]) + " -e " + str(comp3[2]) + " -a", shell=True)
p1.wait()
p2.wait()
p3.wait()
</code></pre>
<p>这可能不是最好的办法。阅读子流程文档,了解为什么<code>shell=True</code>并传递字符串通常不如传递参数的<code>list</code>,以及管理子流程的其他方法等。。但同时,这可能是你已经拥有的最简单的改变。在</p>
<p>另一种选择是,首先不要对<code>ssh</code>命令执行shell操作,而是使用类似于<a href="http://www.lag.net/paramiko/" rel="nofollow">^{<cd8>}</a>的方法从Python中生成远程进程。在</p>