import sys try: print("stuff") except: sys.exit(1) # exiing with a non zero value is better for returning from an error