Workaround a python bug with KeyboardInterrupt
Add some safeguards