擅长:python、mysql、java
<p>您想使用<code>Popen</code>。下面是<code>subprocess.call</code>的样子:</p>
<pre><code>def call(*popenargs, timeout=None, **kwargs):
"""Run command with arguments. Wait for command to complete or
timeout, then return the returncode attribute.
The arguments are the same as for the Popen constructor. Example:
retcode = call(["ls", "-l"])
"""
with Popen(*popenargs, **kwargs) as p:
try:
return p.wait(timeout=timeout)
except: # Including KeyboardInterrupt, wait handled that.
p.kill()
# We don't call p.wait() again as p.__exit__ does that for us.
raise
</code></pre>
<p><code>subprocess.call</code>专门用于在返回之前等待进程完成。所以,当<code>subprocess.call</code>结束时,没有什么可杀的了</p>
<p>如果您想启动一个子流程,然后在它运行时执行其他操作,包括终止该流程,那么应该直接使用<code>subprocess.Popen</code></p>