Commits

ana-balica committed 636b2ee

use instance variable for locking the email sending in EmailHandler

Comments (0)

Files changed (1)

 
 configured = False
 fallback_config = False
-in_email_handler = False
 
 import warnings
 
             toaddrs = [toaddrs]
         self.toaddrs = toaddrs
         self.subject = subject
+        self.in_email_handler = False
 
     def emit(self, record):
         """ Emit a record.
         if not app.cfg.email_tracebacks:
             return
 
-        global in_email_handler
-        if in_email_handler:
+        if self.in_email_handler:
             return
-        in_email_handler = True
-        toaddrs = self.toaddrs if self.toaddrs else app.cfg.admin_emails
-        log_level = logging.getLevelName(self.level)
-        subject = self.subject if self.subject else u'[{0}][{1}] Log message'.format(
-            app.cfg.sitename, log_level)
-        msg = self.format(record)
-        from MoinMoin.mail.sendmail import sendmail
-        sendmail(subject, msg, to=toaddrs)
-        in_email_handler = False
+        self.in_email_handler = True
+        try:
+            toaddrs = self.toaddrs if self.toaddrs else app.cfg.admin_emails
+            log_level = logging.getLevelName(self.level)
+            subject = self.subject if self.subject else u'[{0}][{1}] Log message'.format(
+                app.cfg.sitename, log_level)
+            msg = self.format(record)
+            from MoinMoin.mail.sendmail import sendmail
+            sendmail(subject, msg, to=toaddrs)
+        finally:
+            self.in_email_handler = False