I really don't know why you want to do this, but you can install an excepthook that Python will call whenever an exception is thrown, and it clears the array of the registered function in the atexit module.
Something like that:
import sys import atexit def clear_atexit_excepthook(exctype, value, traceback): atexit._exithandlers[:] = [] sys.__excepthook__(exctype, value, traceback) def helloworld(): print "Hello world!" sys.excepthook = clear_atexit_excepthook atexit.register(helloworld) raise Exception("Good bye cruel world!")
Beware that it can behave incorrectly if an exception arises from the registered atexit function (but then the behavior would be strange even if this hook was not used).
source share