From ff31d6c02336f5c185b70e1bc451c0250b43ad31 Mon Sep 17 00:00:00 2001 From: Harmon Date: Sat, 23 Jan 2021 11:18:44 -0600 Subject: [PATCH] Remove Stream._read_loop --- tweepy/streaming.py | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/tweepy/streaming.py b/tweepy/streaming.py index 2e0ec13..5f4d079 100644 --- a/tweepy/streaming.py +++ b/tweepy/streaming.py @@ -191,7 +191,20 @@ class Stream: http_error_wait = http_error_wait_start network_error_wait = network_error_wait_step self.listener.on_connect() - self._read_loop(resp) + + for line in resp.iter_lines( + chunk_size=self.chunk_size + ): + if not self.running: + break + if not line: + self.listener.on_keep_alive() + elif self.listener.on_data(line) is False: + self.running = False + break + + if resp.raw.closed: + self.on_closed(resp) except (requests.ConnectionError, requests.Timeout, ssl.SSLError, urllib3.exceptions.ReadTimeoutError, urllib3.exceptions.ProtocolError) as exc: @@ -217,19 +230,6 @@ class Stream: self.session.close() self.running = False - def _read_loop(self, resp): - for line in resp.iter_lines(chunk_size=self.chunk_size): - if not self.running: - break - if not line: - self.listener.on_keep_alive() - elif self.listener.on_data(line) is False: - self.running = False - break - - if resp.raw.closed: - self.on_closed(resp) - def _start(self, *args, threaded=False, **kwargs): self.running = True if threaded: -- 2.25.1