Implement StreamListener.on_connect callback.
authorJoshua Roesslein <jroesslein@gmail.com>
Sun, 19 May 2013 06:58:26 +0000 (23:58 -0700)
committerJoshua Roesslein <jroesslein@gmail.com>
Sun, 19 May 2013 06:58:26 +0000 (23:58 -0700)
tweepy/streaming.py

index b1bb4b24002d7b33a85b5b9d27a3293b7c9d4dec..f6d37f450111166bfb67d22b93177c2894275ce9 100644 (file)
@@ -22,6 +22,15 @@ class StreamListener(object):
     def __init__(self, api=None):
         self.api = api or API()
 
+    def on_connect(self):
+        """Called once connected to streaming server.
+
+        This will be invoked once a successful response
+        is received from the server. Allows the listener
+        to perform some work prior to entering the read loop.
+        """
+        pass
+
     def on_data(self, data):
         """Called when raw data is received from connection.
 
@@ -114,6 +123,7 @@ class Stream(object):
                     sleep(self.retry_time)
                 else:
                     error_counter = 0
+                    self.listener.on_connect()
                     self._read_loop(resp)
             except timeout:
                 if self.listener.on_timeout() == False: