Python关闭子进程
我有一个非常简单的问题,关于在用python 3编写的脚本中杀死子进程 在哪里, 如果我有Python关闭子进程,python,windows,web-services,file,web-applications,Python,Windows,Web Services,File,Web Applications,我有一个非常简单的问题,关于在用python 3编写的脚本中杀死子进程 在哪里, 如果我有 my_process = None def open_storage(): my_process = subprocess.Popen("waffles.exe") def kill_children(): my_process.kill() 调用open\u storage()后,如果调用kill\u children(),我会得到 AttributeError:“非类型”对象没有
my_process = None
def open_storage():
my_process = subprocess.Popen("waffles.exe")
def kill_children():
my_process.kill()
调用open\u storage()
后,如果调用kill\u children()
,我会得到
AttributeError:“非类型”对象没有属性“kill”
但是如果我有
my_进程=无
my_process = subprocess.Popen("waffles.exe")
def kill_children():
my_process.kill()
一切正常
有人能解释这种奇怪的行为吗?我需要将open_storage()
作为一个函数,因为它是由tkinter按钮触发的
谢谢。您需要使用全局变量,否则它将使用局部变量
def open_storage():
global my_process
my_process = subprocess.Popen("waffles.exe")