From ecdc8b54afee385f9bb0cacdcca6b2881a965a52 Mon Sep 17 00:00:00 2001 From: Josh Roesslein Date: Thu, 3 Sep 2009 12:49:35 -0500 Subject: [PATCH] Added on_timeout() to stream listener. --- streamwatcher.py | 3 +++ tweepy/streaming.py | 7 ++++++- 2 files changed, 9 insertions(+), 1 deletion(-) 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() -- 2.25.1