def initHooks(global_exceptions=True, thread_exceptions=True, pass_original=True):
 def excepthook(*exception_info):
  try:
   message = ''.join(traceback.format_exception(*exception_info))
   logger.error('Uncaught exception: %s', message)
  except:
   pass
  if pass_original:
   sys.__excepthook__(*exception_info)
 if global_exceptions:
  sys.excepthook = excepthook
 if thread_exceptions:
  old_init = threading.Thread.__init__
  def new_init(self, *args, **kwargs):
   old_init(self, *args, **kwargs)
   old_run = self.run
   def new_run(*args, **kwargs):
    try:
     old_run(*args, **kwargs)
    except (KeyboardInterrupt, SystemExit):
     raise
    except:
     excepthook(*sys.exc_info())
   self.run = new_run
  threading.Thread.__init__ = new_init

def initHooks ( global_exceptions = True , thread_exceptions = True , pass_original = True ) : def excepthook ( * exception_info ) : try : message = '' . join ( traceback . format_exception ( * exception_info ) ) logger . error ( 'Uncaught exception: %s' , message ) except : pass if pass_original : sys . __excepthook__ ( * exception_info ) if global_exceptions : sys . excepthook = excepthook if thread_exceptions : old_init = threading . Thread . __init__ def new_init ( self , * args , ** kwargs ) : old_init ( self , * args , ** kwargs ) old_run = self . run def new_run ( * args , ** kwargs ) : try : old_run ( * args , ** kwargs ) except ( KeyboardInterrupt , SystemExit ) : raise except : excepthook ( * sys . exc_info ( ) ) self . run = new_run threading . Thread . __init__ = new_init
this method installs exception catching mechanisms .