code: def email_uncaught_exception(func):
      
      @wraps(func)
      def wrapper(*args, **kwargs):
          try:
              func(*args, **kwargs)
          except:
              logger = logging.getLogger('dbbackup')
              exc_type, exc_value, tb = sys.exc_info()
              tb_str = ''.join(traceback.format_tb(tb))
              msg = '%s: %s\n%s' % (exc_type.__name__, exc_value, tb_str)
              logger.error(msg)
              raise
          finally:
              connection.close()
      return wrapper
docs: Function decorator for send email with uncaught exceptions to admins.
      Email is sent to ``settings.DBBACKUP_FAILURE_RECIPIENTS``
      (``settings.ADMINS`` if not defined). The message contains a traceback
      of error.