Skip to content

Commit

Permalink
Check that the response is not closed each time around the loop.
Browse files Browse the repository at this point in the history
  • Loading branch information
Dan Fairs committed Feb 4, 2012
1 parent a6d701d commit c2edbea
Showing 1 changed file with 15 additions and 18 deletions.
33 changes: 15 additions & 18 deletions tweepy/streaming.py
Expand Up @@ -141,25 +141,22 @@ def _data(self, data):
self.running = False

def _read_loop(self, resp):
while self.running:
if resp.isclosed():
break
buf = ''
while self.running and not resp.isclosed():
c = resp.read(self.buffer_size)
idx = c.rfind('\n')
if idx > -1:
# There is an index. Store the tail part for later,
# and process the head part as messages. We use idx + 1
# as we dont' actually want to store the newline.
data = buf + c[:idx]
buf = c[idx + 1:]
self._data(data)
else:
# No newline found, so we add this to our accumulated
# buffer
buf += c

buf = ''
while True:
c = resp.read(self.buffer_size)
idx = c.rfind('\n')
if idx > -1:
# There is an index. Store the tail part for later,
# and process the head part as messages. We use idx + 1
# as we dont' actually want to store the newline.
data = buf + c[:idx]
buf = c[idx + 1:]
self._data(data)
else:
# No newline found, so we add this to our accumulated
# buffer
buf += c

def _start(self, async):
self.running = True
Expand Down

0 comments on commit c2edbea

Please sign in to comment.