I want to execute some bash script upon keyboard interrupt but it seems my python code is exiting without executing the bash script at keyboard interrupt.here is my sample code.
from flask import Flask
import os
#here resides my flask code
try:
if __name__ == '__main__':
app.run()
except (KeyboardInterrupt, SystemExit):
os.system('echo "running bash script from python"')
os.system('netstat --listen')
os.system('sudo service apache2 start')
exit()