Skip to content

Commit

Permalink
feat: reuse request sessions
Browse files Browse the repository at this point in the history
  • Loading branch information
user2589 committed Sep 24, 2019
1 parent 5e84046 commit 6ba014f
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions stgithub.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ def __new__(cls, *args, **kwargs): # Singleton
return cls._instance

def __init__(self):
self.cookies = requests.get(BASE_URL).cookies
self.session = requests.Session()
self.queue = six.moves.queue.Queue(maxsize=self.queue_max_size)

@guard
Expand All @@ -382,8 +382,7 @@ def _request(self, url, params=None, headers=None):
r = None
for _ in range(self.retries_on_timeout):
try:
r = requests.get(url, cookies=self.cookies,
headers=headers, params=params)
r = self.session.get(url, headers=headers, params=params)
except requests.exceptions.RequestException:
time.sleep(1)
continue
Expand Down

0 comments on commit 6ba014f

Please sign in to comment.