I write code in Python like this:
import sys try: for x in large_list: function_that_catches_KeyboardInterrupt(x) except KeyboardInterrupt: print "Canceled!" sys.exit(1)
When I try to abort the loop, I basically need to hold Control + C long enough to cancel all function calls for all large-list items, and only then will my program exit.
Is there any way to prevent functions from intercepting KeyboardInterrupt so that I can catch it myself? The only way I can think of is to abuse the threads by creating a separate thread just for calling the function, but that seems excessive.
Edit: I checked the violation code (which I cannot easily change), and in fact it uses bare except: so even sys.exit(1) is called as a SystemExit exception. How can I escape from the bare except: block and exit my program?
source share