If I have
my_process = None
def open_storage():
my_process = subprocess.Popen("waffles.exe")
def kill_children():
my_process.kill()
After calling open_storage(), if I call kill_children(), I get
AttributeError: 'NoneType' object has no attribute 'kill'
But if I have,
my_process = None
my_process = subprocess.Popen("waffles.exe")
def kill_children():
my_process.kill()
Everything works fine.
Can anyone explain this strange behaviour? I need to have open_storage() as a function because it's designed to be triggered by a tkinter button.
You need to use global, otherwise it will use a local variable.
def open_storage():
global my_process
my_process = subprocess.Popen("waffles.exe")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With