From: Josh Roesslein Date: Thu, 3 Sep 2009 17:49:35 +0000 (-0500) Subject: Added on_timeout() to stream listener. X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=ecdc8b54afee385f9bb0cacdcca6b2881a965a52;p=tweepy.git Added on_timeout() to stream listener. --- diff --git a/streamwatcher.py b/streamwatcher.py index 8c8df3d..3012088 100755 --- a/streamwatcher.py +++ b/streamwatcher.py @@ -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: ') diff --git a/tweepy/streaming.py b/tweepy/streaming.py index 50ec049..9a97850 100644 --- a/tweepy/streaming.py +++ b/tweepy/streaming.py @@ -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()