Skip to content

Commit 30e3bad

Browse files
committed
- added back the use of sessions to improve the performance and reuse of open ports
1 parent 0c9769e commit 30e3bad

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

eventregistry/EventRegistry.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ def __init__(self,
4949

5050
# lock for making sure we make one request at a time - requests module otherwise sometimes returns incomplete json objects
5151
self._lock = threading.Lock()
52+
self._reqSession = requests.Session()
5253
self._apiKey = apiKey
5354
self._extraParams = None
5455

@@ -86,7 +87,7 @@ def checkVersion(self):
8687
check what is the latest version of the python sdk and report in case there is a newer version
8788
"""
8889
try:
89-
respInfo = requests.get(self._host + "/static/pythonSDKVersion.txt")
90+
respInfo = self._reqSession.get(self._host + "/static/pythonSDKVersion.txt")
9091
if respInfo.status_code != 200 or len(respInfo.text) > 20:
9192
return
9293
latestVersion = respInfo.text.strip()
@@ -258,7 +259,7 @@ def jsonRequest(self, methodUrl, paramDict, customLogFName = None, allowUseOfArc
258259
url = self._host + methodUrl
259260

260261
# make the request
261-
respInfo = requests.post(url, json = paramDict)
262+
respInfo = self._reqSession.post(url, json = paramDict)
262263
# remember the returned headers
263264
self._headers = respInfo.headers
264265
# if we got some error codes print the error and repeat the request after a short time period
@@ -311,7 +312,7 @@ def jsonRequestAnalytics(self, methodUrl, paramDict):
311312
tryCount += 1
312313
try:
313314
# make the request
314-
respInfo = requests.post(self._hostAnalytics + methodUrl, json = paramDict)
315+
respInfo = self._reqSession.post(self._hostAnalytics + methodUrl, json = paramDict)
315316
# remember the returned headers
316317
self._headers = respInfo.headers
317318
# if we got some error codes print the error and repeat the request after a short time period

0 commit comments

Comments
 (0)