Added on_timeout() to stream listener.
authorJosh Roesslein <jroesslein@gmail.com>
Thu, 3 Sep 2009 17:49:35 +0000 (12:49 -0500)
committerJosh Roesslein <jroesslein@gmail.com>
Thu, 3 Sep 2009 17:49:35 +0000 (12:49 -0500)
streamwatcher.py
tweepy/streaming.py

index 8c8df3d5afb4841ea7e2b1e655e67fd34ec0a7eb..3012088991f8b7165e2e5a0147ffffa4dea534d5 100755 (executable)
@@ -14,6 +14,9 @@ class StreamWatcherListener(tweepy.StreamListener):
     print 'An error has occured! Status code = %s' % status_code
     return True  # keep stream alive
 
+  def on_timeout(self):
+    print 'Snoozing Zzzzzz'
+
 # Prompt for login credentials and setup stream object
 username = raw_input('Twitter username: ')
 password = getpass('Twitter password: ')
index 50ec049c0e612b7d1bb4328e8ca191c77d656064..9a9785046735f6732d3383000f83e4ce3100a091 100644 (file)
@@ -37,6 +37,10 @@ class StreamListener(object):
     """Called when a non-200 status code is returned"""
     return False
 
+  def on_timeout(self):
+    """Called when stream connection times out"""
+    return 
+
 class Stream(object):
 
   host = 'stream.twitter.com'
@@ -80,7 +84,8 @@ class Stream(object):
           error_counter = 0
           self._read_loop(resp)
       except timeout:
-        print 'timeout!'
+        if self.listener.on_timeout() == False:
+          break
         if self.running is False:
           break
         conn.close()