From 272bf5ffcf650ec48f00ad9a9824b6e8f6623a08 Mon Sep 17 00:00:00 2001 From: nschwane Date: Mon, 5 Mar 2012 14:50:40 -0500 Subject: [PATCH] Added a timeout setting to use with urllib2 when retrieving an image with a URL. Without the timeout setting, urllib2 will wait indefinitely for a response. --- sorl/thumbnail/conf/defaults.py | 3 +++ sorl/thumbnail/images.py | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/sorl/thumbnail/conf/defaults.py b/sorl/thumbnail/conf/defaults.py index a039ca9bf..f5a7c494b 100644 --- a/sorl/thumbnail/conf/defaults.py +++ b/sorl/thumbnail/conf/defaults.py @@ -81,3 +81,6 @@ # or height given THUMBNAIL_DUMMY_RATIO = 1.5 +# Timeout, in seconds, to use when retrieving images with urllib2 +THUMBNAIL_URL_TIMEOUT = None + diff --git a/sorl/thumbnail/images.py b/sorl/thumbnail/images.py index 515024e62..f9bc2c7c7 100644 --- a/sorl/thumbnail/images.py +++ b/sorl/thumbnail/images.py @@ -166,7 +166,7 @@ def url(self): class UrlStorage(Storage): def open(self, name): - return urllib2.urlopen(name) + return urllib2.urlopen(name, None, settings.THUMBNAIL_URL_TIMEOUT) def exists(self, name): try: