summaryrefslogtreecommitdiffstats
path: root/Lib/logging
diff options
context:
space:
mode:
authorVinay Sajip <vinay_sajip@yahoo.co.uk>2012-03-15 12:02:08 (GMT)
committerVinay Sajip <vinay_sajip@yahoo.co.uk>2012-03-15 12:02:08 (GMT)
commit17160fd6d6d7850294a9a465a3e5e399e5028bb6 (patch)
tree0ba75e61d7a0e93d7b7a86e9e66da834462a20ef /Lib/logging
parent7cc7033cb428ad74366f93e8ebcb4bb74f3f6511 (diff)
downloadcpython-17160fd6d6d7850294a9a465a3e5e399e5028bb6.zip
cpython-17160fd6d6d7850294a9a465a3e5e399e5028bb6.tar.gz
cpython-17160fd6d6d7850294a9a465a3e5e399e5028bb6.tar.bz2
Fixes #14314: Improved SMTP timeout handling.
Diffstat (limited to 'Lib/logging')
-rw-r--r--Lib/logging/handlers.py7
1 files changed, 5 insertions, 2 deletions
diff --git a/Lib/logging/handlers.py b/Lib/logging/handlers.py
index bebd79a..f8632ce 100644
--- a/Lib/logging/handlers.py
+++ b/Lib/logging/handlers.py
@@ -867,7 +867,7 @@ class SMTPHandler(logging.Handler):
A handler class which sends an SMTP email for each logging event.
"""
def __init__(self, mailhost, fromaddr, toaddrs, subject,
- credentials=None, secure=None):
+ credentials=None, secure=None, timeout=1.0):
"""
Initialize the handler.
@@ -881,6 +881,8 @@ class SMTPHandler(logging.Handler):
will be either an empty tuple, or a single-value tuple with the name
of a keyfile, or a 2-value tuple with the names of the keyfile and
certificate file. (This tuple is passed to the `starttls` method).
+ A timeout in seconds can be specified for the SMTP connection (the
+ default is one second).
"""
logging.Handler.__init__(self)
if isinstance(mailhost, tuple):
@@ -897,6 +899,7 @@ class SMTPHandler(logging.Handler):
self.toaddrs = toaddrs
self.subject = subject
self.secure = secure
+ self.timeout = timeout
def getSubject(self, record):
"""
@@ -919,7 +922,7 @@ class SMTPHandler(logging.Handler):
port = self.mailport
if not port:
port = smtplib.SMTP_PORT
- smtp = smtplib.SMTP(self.mailhost, port)
+ smtp = smtplib.SMTP(self.mailhost, port, timeout=self.timeout)
msg = self.format(record)
msg = "From: %s\r\nTo: %s\r\nSubject: %s\r\nDate: %s\r\n\r\n%s" % (
self.fromaddr,