Skip to content

Commit

Permalink
Remove Stream.new_session
Browse files Browse the repository at this point in the history
Stop unnecessarily creating a new requests Session at the end of each call to Stream._run
  • Loading branch information
Harmon758 committed Jan 22, 2021
1 parent 5f57916 commit 26518ab
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions tweepy/streaming.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,18 +144,17 @@ def __init__(self, auth, listener, **options):

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
Expand Down Expand Up @@ -212,7 +211,6 @@ def _run(self, params=None, body=None):
raise
finally:
self.running = False
self.new_session()

def _read_loop(self, resp):
for line in resp.iter_lines(chunk_size=self.chunk_size):
Expand Down

0 comments on commit 26518ab

Please sign in to comment.