Don't set the global socket timeout
authorJaime Marquínez Ferrándiz <jaime.marquinez.ferrandiz@gmail.com>
Mon, 10 Mar 2014 18:01:29 +0000 (19:01 +0100)
committerJaime Marquínez Ferrándiz <jaime.marquinez.ferrandiz@gmail.com>
Mon, 10 Mar 2014 18:03:37 +0000 (19:03 +0100)
Use the timeout argument of the `OpenerDirector.open` method instead

youtube_dl/YoutubeDL.py

index 523eba3c1e1287c6813de63825613ab39d63d8a7..c1bd0b0859ea4007cda997674915374f9d062f42 100644 (file)
@@ -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)