summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMalcolm Tredinnick <malcolm.tredinnick@gmail.com>2007-02-17 06:01:17 +0000
committerMalcolm Tredinnick <malcolm.tredinnick@gmail.com>2007-02-17 06:01:17 +0000
commitf5ede9c5c8bb2ebef362b374330c6d1200e6706b (patch)
tree44200559d20e982821466ce6fcdf4216ec675b76
parented3d787edaecdaaece247d7b0f09b9ed6fe3be84 (diff)
Fixed #3067 -- Improved caching of machine hostname to increase server restart
times. Thanks SmileyChris. git-svn-id: http://code.djangoproject.com/svn/django/trunk@4536 bcc190cf-cafb-0310-a4f2-bffc1f526a37
-rw-r--r--django/core/mail.py13
1 files changed, 12 insertions, 1 deletions
diff --git a/django/core/mail.py b/django/core/mail.py
index a5af6e610f..cc99659adb 100644
--- a/django/core/mail.py
+++ b/django/core/mail.py
@@ -8,7 +8,18 @@ import socket
import time
import random
-DNS_NAME = socket.getfqdn() # Cache the hostname
+# Cache the hostname, but do it lazily: socket.getfqdn() can take a couple of
+# seconds, which slows down the restart of the server.
+class CachedDnsName(object):
+ def __str__(self):
+ return self.get_fqdn()
+
+ def get_fqdn(self):
+ if not hasattr(self, '_fqdn'):
+ self._fqdn = socket.getfqdn()
+ return self._fqdn
+
+DNS_NAME = CachedDnsName()
class BadHeaderError(ValueError):
pass