From 26518abe993b3cf7729e9d55be571b4cc89f50ab Mon Sep 17 00:00:00 2001 From: Harmon Date: Fri, 22 Jan 2021 17:53:55 -0600 Subject: [PATCH] Remove Stream.new_session Stop unnecessarily creating a new requests Session at the end of each call to Stream._run --- tweepy/streaming.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/tweepy/streaming.py b/tweepy/streaming.py index a664cd4..5323cba 100644 --- a/tweepy/streaming.py +++ b/tweepy/streaming.py @@ -144,18 +144,17 @@ class Stream: self.verify = options.get("verify", True) - self.new_session() + self.session = None self.retry_time = self.retry_time_start self.snooze_time = self.snooze_time_step # Example: proxies = {'http': 'http://localhost:1080', 'https': 'http://localhost:1080'} self.proxies = options.get("proxies") - def new_session(self): - self.session = requests.Session() - def _run(self, params=None, body=None): # Authenticate + if self.session is None: + self.session = requests.Session() url = f"https://stream.twitter.com{self.url}" # Connect and process the stream @@ -212,7 +211,6 @@ class Stream: raise finally: self.running = False - self.new_session() def _read_loop(self, resp): for line in resp.iter_lines(chunk_size=self.chunk_size): -- 2.25.1