From 5d275bc778c3042e39d7a7a4c1221d0f7fc8fdac Mon Sep 17 00:00:00 2001 From: Steve Jones Date: Mon, 16 Apr 2012 22:55:48 -0300 Subject: [PATCH] Update to streaming read loop to use delimited stream mode. 1) read newlines until a digit appears 2) read rest of digits until another new line appears 3) read next status object 4) repeat -improved speed over trunk version -simplify loop logic -added condition for "self.running and not resp.isclosed()" during each read-loop stage --- tweepy/streaming.py | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/tweepy/streaming.py b/tweepy/streaming.py index b3d57f3..e9d6d66 100644 --- a/tweepy/streaming.py +++ b/tweepy/streaming.py @@ -147,18 +147,14 @@ class Stream(object): # Note: keep-alive newlines might be inserted before each length value. # read until we get a digit... - c = '' - while c not in digits: + c = '\n' + while c == '\n' and self.running and not resp.isclosed(): c = resp.read(1) delimited_string = c # read rest of delimiter length.. - while 1: - d = resp.read(1) - if d in digits: - delimited_string += d - else: - break + while d != '\n' and self.running and not resp.isclosed(): + delimited_string += resp.read(1) # read the next twitter status object if delimited_string.isdigit(): -- 2.25.1