added timeout to api constructor with default 60s, set timeout when creating HTTPConn...
authordrevicko <subscriptions@drevicko.com>
Sun, 28 Apr 2013 08:33:22 +0000 (18:33 +1000)
committerdrevicko <subscriptions@drevicko.com>
Sun, 28 Apr 2013 08:33:22 +0000 (18:33 +1000)
modified:   tweepy/api.py
modified:   tweepy/binder.py

tweepy/api.py
tweepy/binder.py

index 1eaaf9102a174bbbc83fe66f4f6fbbbfa8bc42a4..39246523423d05c0c0d6d7463439c04ac8ec690e 100644 (file)
@@ -17,7 +17,7 @@ class API(object):
     def __init__(self, auth_handler=None,
             host='api.twitter.com', search_host='search.twitter.com',
              cache=None, secure=True, api_root='/1.1', search_root='',
-            retry_count=0, retry_delay=0, retry_errors=None,
+            retry_count=0, retry_delay=0, retry_errors=None, timeout=60,
             parser=None):
         self.auth = auth_handler
         self.host = host
@@ -29,6 +29,7 @@ class API(object):
         self.retry_count = retry_count
         self.retry_delay = retry_delay
         self.retry_errors = retry_errors
+        self.timeout = timeout
         self.parser = parser or ModelParser()
 
     """ statuses/home_timeline """
index 7817537c92daa423ea221450a7c4cee93e20d65c..528021dec3cd0625df03ca314e87959f72f1dede 100644 (file)
@@ -130,9 +130,9 @@ def bind_api(**config):
                 # Open connection
                 # FIXME: add timeout
                 if self.api.secure:
-                    conn = httplib.HTTPSConnection(self.host)
+                    conn = httplib.HTTPSConnection(self.host,timeout=self.api.timeout)
                 else:
-                    conn = httplib.HTTPConnection(self.host)
+                    conn = httplib.HTTPConnection(self.host,timeout=self.api.timeout)
 
                 # Apply authentication
                 if self.api.auth: