【发布时间】:2015-08-30 17:04:28
【问题描述】:
我正在开发 Widnows 7(32 位),这是我的代码:
def start_mviewer_broker(broker_path, test_name):
""" The function starts the broker server"""
try:
print("**** start_mviewer_broker ****")
p = subprocess.Popen('start python ' + broker_path + ' ' + test_name, shell=True)
return p
except:
print("**** start_mviewer_broker - EXCEPTION ****")
return 0
def kill_process(p):
""" The function kills the input running process"""
try:
print("**** kill_process ****")
p.terminate()
except:
print("**** kill_process - EXCEPTION ****")
pass
我有一些问题。启动我的子进程的唯一方法是使用 shell=True 选项。如果我将此选项更改为 False,则不会启动子进程。
其他问题是 kill 进程不会杀死我的进程,但不会引发异常。
有什么想法吗?
【问题讨论】:
-
start不是一个可执行文件,而是一个 cmd 命令,所以在使用它时你总是必须使用shell=True。返回的进程不是python进程,而是用来生成它的shell,所以杀死它不会有你想要的效果。不要使用start。 -
好的!非常感谢您。现在,没有开始一切都按我的意愿进行。
标签: python subprocess