From: Harmon Date: Fri, 22 Jan 2021 23:53:55 +0000 (-0600) Subject: Remove Stream.new_session X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=26518abe993b3cf7729e9d55be571b4cc89f50ab;p=tweepy.git Remove Stream.new_session Stop unnecessarily creating a new requests Session at the end of each call to Stream._run --- 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):