code_junkie

How to skip sys.exitfunc when unhandled exceptions occur

Nov 10th, 2011
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. import atexit
  2.  
  3. def helloworld():
  4. print "Hello World!"
  5.  
  6. atexit.register(helloworld)
  7.  
  8. raise Exception("Good bye cruel world!")
  9.  
  10. import sys
  11. import atexit
  12.  
  13. def clear_atexit_excepthook(exctype, value, traceback):
  14. atexit._exithandlers[:] = []
  15. sys.__excepthook__(exctype, value, traceback)
  16.  
  17. def helloworld():
  18. print "Hello world!"
  19.  
  20. sys.excepthook = clear_atexit_excepthook
  21. atexit.register(helloworld)
  22.  
  23. raise Exception("Good bye cruel world!")
  24.  
  25. import os
  26. os._exit(0)
  27.  
  28. import atexit
  29. import os
  30.  
  31. def helloworld():
  32. print "Hello World!"
  33.  
  34. atexit.register(helloworld)
  35.  
  36. try:
  37. raise Exception("Good bye cruel world!")
  38.  
  39. except Exception, e:
  40. print 'caught unhandled exception', str(e)
  41.  
  42. os._exit(1)
Add Comment
Please, Sign In to add comment