# HG changeset patch # User Brian Neal # Date 1444952156 18000 # Node ID 3ebde23a59d0d365134409dded8346c51746d61d # Parent a6331579ff4378b236256b5294785651485a7a1d Pass timeout to requests instead of global timeout. Global timeout didn't seem to work once we started using requests. diff -r a6331579ff43 -r 3ebde23a59d0 core/download.py --- a/core/download.py Fri Oct 09 22:20:32 2015 -0500 +++ b/core/download.py Thu Oct 15 18:35:56 2015 -0500 @@ -12,7 +12,7 @@ logger = logging.getLogger(__name__) -def download_file(url, path=None): +def download_file(url, path=None, timeout=None): """Downloads the image file from the given source URL and stores it in the filename given by path. If path is None, a temporary file will be created. @@ -24,7 +24,7 @@ logger.info("download_file from %s; path=%s", url, path) try: - r = requests.get(url, stream=True) + r = requests.get(url, stream=True, timeout=timeout) except requests.RequestException: logger.exception("download_file requests.get('%s') exception", url) raise diff -r a6331579ff43 -r 3ebde23a59d0 core/management/commands/ssl_images.py --- a/core/management/commands/ssl_images.py Fri Oct 09 22:20:32 2015 -0500 +++ b/core/management/commands/ssl_images.py Thu Oct 15 18:35:56 2015 -0500 @@ -14,7 +14,6 @@ import os import re import signal -import socket import urlparse import uuid @@ -54,6 +53,7 @@ bucket = None url_cache = {} bad_hosts = set() +request_timeout = None def signal_handler(signum, frame): @@ -145,7 +145,7 @@ url = parsed_url.geturl() fn = None try: - fn = download_file(url) + fn = download_file(url, timeout=request_timeout) except requests.ConnectionError as ex: logger.error("ConnectionError, ignoring host %s", parsed_url.hostname) bad_hosts.add(parsed_url.hostname) @@ -250,9 +250,9 @@ type='int', help="optional second slice index; the j in [i:j]"), make_option('-t', '--timeout', - type='int', + type='float', help="optional socket timeout (secs)", - default=30), + default=30.0), ) def handle_noargs(self, **options): @@ -289,9 +289,9 @@ qs = qs[:j] # Set global socket timeout - timeout = options.get('timeout') - logger.info("Setting socket timeout to %d", timeout) - socket.setdefaulttimeout(timeout) + global request_timeout + request_timeout = options.get('timeout') + logger.info("Using socket timeout of %4.2f", request_timeout) # Install signal handler for ctrl-c signal.signal(signal.SIGINT, signal_handler)