From: Steve Jones Date: Tue, 17 Apr 2012 01:55:48 +0000 (-0300) Subject: Update to streaming read loop to use delimited stream mode. X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=5d275bc778c3042e39d7a7a4c1221d0f7fc8fdac;p=tweepy.git 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 --- 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():