From 19a41fc613b78073de44407703f53347d44667d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaime=20Marqui=CC=81nez=20Ferra=CC=81ndiz?= Date: Mon, 10 Mar 2014 19:01:29 +0100 Subject: [PATCH 1/2] Don't set the global socket timeout Use the timeout argument of the `OpenerDirector.open` method instead --- youtube_dl/YoutubeDL.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/youtube_dl/YoutubeDL.py b/youtube_dl/YoutubeDL.py index 523eba3c1..c1bd0b085 100644 --- a/youtube_dl/YoutubeDL.py +++ b/youtube_dl/YoutubeDL.py @@ -1167,7 +1167,7 @@ class YoutubeDL(object): def urlopen(self, req): """ Start an HTTP download """ - return self._opener.open(req) + return self._opener.open(req, timeout=self._socket_timeout) def print_debug_header(self): if not self.params.get('verbose'): @@ -1198,7 +1198,7 @@ class YoutubeDL(object): def _setup_opener(self): timeout_val = self.params.get('socket_timeout') - timeout = 600 if timeout_val is None else float(timeout_val) + self._socket_timeout = 600 if timeout_val is None else float(timeout_val) opts_cookiefile = self.params.get('cookiefile') opts_proxy = self.params.get('proxy') @@ -1239,4 +1239,3 @@ class YoutubeDL(object): # TODO remove this global modification compat_urllib_request.install_opener(opener) - socket.setdefaulttimeout(timeout) From a0792b738ed51ca61eed36ff1dba41d05141093c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaime=20Marqui=CC=81nez=20Ferra=CC=81ndiz?= Date: Mon, 10 Mar 2014 19:04:30 +0100 Subject: [PATCH 2/2] Don't install the global url opener All the code uses now the urlopen method of YoutubeDL --- youtube_dl/YoutubeDL.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/youtube_dl/YoutubeDL.py b/youtube_dl/YoutubeDL.py index c1bd0b085..1db27315c 100644 --- a/youtube_dl/YoutubeDL.py +++ b/youtube_dl/YoutubeDL.py @@ -1236,6 +1236,3 @@ class YoutubeDL(object): # (See https://github.com/rg3/youtube-dl/issues/1309 for details) opener.addheaders = [] self._opener = opener - - # TODO remove this global modification - compat_urllib_request.install_opener(opener)