在Python中,可以使用team
模块轻松启动外部进程。例如在Windows上:
subprocess
要终止该过程,我们可以运行:
command = 'external_app'
my_process = subprocess.Popen(
command,
creationflags=subprocess.CREATE_NEW_PROCESS_GROUP,
shell=True,
stderr=subprocess.STDOUT,
stdout=subprocess.PIPE,
universal_newlines=True)
使用Python的命令行解释器(os.kill(my_process.pid, signal.CTRL_BREAK_EVENT)
)可以正常工作。但是,如果我想在没有使用python.exe
的命令行窗口的情况下从图形Python应用程序中启动和停止进程,则会出现问题,即我无法再使用pythonw.exe
停止该进程。
如何使用os.kill
?