This issue has been driving me nuts over the past few days. I have a script that I wish to terminate upon the press of a button.
Currently using try/except with KeyboardInterrupt which works fantastically if I actually press ctrl+c on the keyboard, but ultimately the script will be running headless so need the button input.
so far I have got this:
Code: Select all
def killScript(pin):
os.kill(signal.CTRL_C_EVENT)
GPIO.add_event_detect(22, GPIO.RISING, callback=killScript, bouncetime=200)
Traceback (most recent call last):
File "/home/pi/scripts/picam/picam.py", line 50, in killScript
os.kill(signal.CTRL_C_EVENT)
AttributeError: 'module' object has no attribute 'CTRL_C_EVENT'
I'm open to other methods if I've got it all wrapped around my brain and confused!
I don't fully understand signals yet, so any complex terminology may go straight over my head!
Thanks in advance
Mark