Killing a process created with Python's subprocess.Popen() [duplicate]

This question already has an answer here:

Here is my thought:

First of all, I created a process by using subprocess.Popen

Second, after certain amount of time, I tried to kill it by Popen.kill()

import subprocess
import os, signal
import time

proc1 = subprocess.Popen("kvm -hda /path/xp.img", shell = True)
time.sleep(2.0)
print 'proc1 = ', proc1.pid
subprocess.Popen.kill(proc1)

However, "proc1" still exists after Popen.kill(). Could any experts tell me how to solve this issue? Я ценю ваше мнение.

Благодаря комментариям всех экспертов, я сделал все, что вы рекомендовали, но результат остался прежним.

proc1.kill () #it sill не может убить proc1

os.kill(proc1.pid, signal.SIGKILL) # either cannot kill the proc1

Всем спасибо то же самое.

И я все еще жду вашего драгоценного опыта в решении этого деликатного вопроса.

51
задан ThiefMaster 28 March 2013 в 05:30
поделиться