changeset 2308:636b2ee1c5fe

use instance variable for locking the email sending in EmailHandler
author Ana Balica <ana.balica@gmail.com>
date Mon, 18 Nov 2013 16:17:58 +0100
parents 90a17c8544ad
children d5fa8dae5055
files MoinMoin/log.py
diffstat 1 files changed, 13 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/log.py	Sun Nov 17 14:01:14 2013 -0700
+++ b/MoinMoin/log.py	Mon Nov 18 16:17:58 2013 +0100
@@ -103,7 +103,6 @@
 
 configured = False
 fallback_config = False
-in_email_handler = False
 
 import warnings
 
@@ -193,6 +192,7 @@
             toaddrs = [toaddrs]
         self.toaddrs = toaddrs
         self.subject = subject
+        self.in_email_handler = False
 
     def emit(self, record):
         """ Emit a record.
@@ -205,15 +205,16 @@
         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