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: ')
"""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'
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()