子行业Popen挂了

时间:2016-11-02 10:45:46

标签: python

def hello():
    while True:
    	print 'subprocess = ' + str(os.getpid())
    	time.sleep(1)
def killPid(pid):
	print 'kill ' + str(pid)
	os.system("taskkill" + ' /T /F /pid '+ str(pid))

p = subprocess.Popen(hello())
# p = subprocess.Popen("ping 10.193.101.34", shell=True)
print 'after subprocess'
t = threading.Timer(3.0, killPid, args=(p.pid,))
t.start()  # after 3 seconds, "hello, world" will be printed

当ppen挂了? 子进步没有被杀死

1 个答案:

答案 0 :(得分:2)

它想要将函数hello()作为一个进程执行。为此,您可以尝试使用类似

的方式调用Popen
["python","-m",__file__,"-c","hello()"] 

运行执行hello函数的python解释器的新实例。