Skip to content

Commit 7d37765

Browse files
committed
new pool_connections arg
1 parent e15ed4b commit 7d37765

4 files changed

Lines changed: 22 additions & 5 deletions

File tree

‎orthanc_api_client/api_client.py‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,13 @@ def get(self, metric_name: str) -> Optional[str]:
5151

5252
class OrthancApiClient(HttpClient):
5353

54-
def __init__(self, orthanc_root_url: str, user: Optional[str] = None, pwd: Optional[str] = None, api_token: Optional[str] = None, headers: Optional[Dict[str, str]] = None ) -> None:
54+
def __init__(self,
55+
orthanc_root_url: str,
56+
user: Optional[str] = None,
57+
pwd: Optional[str] = None,
58+
api_token: Optional[str] = None,
59+
headers: Optional[Dict[str, str]] = None,
60+
pool_connections: int = 10) -> None:
5561
"""Creates an HttpClient
5662
5763
Parameters
@@ -62,6 +68,8 @@ def __init__(self, orthanc_root_url: str, user: Optional[str] = None, pwd: Optio
6268
api_token: a token obtained from inside an Orthanc python plugin through orthanc.GenerateRestApiAuthorizationToken
6369
format: 'Bearer 3d03892c-fe...' or '3d03892c-fe...'
6470
headers: HTTP headers that will be included in each requests
71+
pool_connections: The number of HTTP connections in the pool (default=10). If you are using the client from more than 10 threads,
72+
you should increase this configuration.
6573
"""
6674
if api_token:
6775
if headers is None:
@@ -72,7 +80,7 @@ def __init__(self, orthanc_root_url: str, user: Optional[str] = None, pwd: Optio
7280
header_value = f'Bearer {api_token}'
7381
headers['authorization'] = header_value
7482

75-
super().__init__(root_url=orthanc_root_url, user=user, pwd=pwd, headers=headers)
83+
super().__init__(root_url=orthanc_root_url, user=user, pwd=pwd, headers=headers, pool_connections=pool_connections)
7684

7785
self.patients = Patients(api_client=self)
7886
self.studies = Studies(api_client=self)

‎orthanc_api_client/http_client.py‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
class HttpClient:
1111

12-
def __init__(self, root_url: str, user: str = None, pwd: str = None, headers: any = None) -> None:
12+
def __init__(self, root_url: str, user: str = None, pwd: str = None, headers: any = None, pool_connections: int = 10) -> None:
1313
self._root_url = root_url
1414
self._http_session = requests.Session()
1515

@@ -31,7 +31,9 @@ def __init__(self, root_url: str, user: str = None, pwd: str = None, headers: an
3131
backoff_factor=0.2
3232
)
3333
url_schema = urllib.parse.urlparse(root_url).scheme + "://"
34-
self._http_session.mount(url_schema, HTTPAdapter(max_retries=retries))
34+
self._http_session.mount(url_schema, HTTPAdapter(max_retries=retries,
35+
pool_connections=pool_connections,
36+
pool_maxsize=pool_connections))
3537

3638

3739
def get_abs_url(self, endpoint: str) -> str:

‎release-notes.md‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
v 0.24.2
2+
========
3+
4+
- new optional `pool_connections` argument when creating an `OrthancApiClient`.
5+
By default, the value is `10` which can create a bottleneck when e.g. 20 worker
6+
threads are using the same client.
7+
18
V 0.24.1
29
========
310

‎setup.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
# For a discussion on single-sourcing the version across setup.py and the
2929
# project code, see
3030
# https://packaging.python.org/guides/single-sourcing-package-version/
31-
version='0.24.1', # Required
31+
version='0.24.2', # Required
3232

3333
# This is a one-line description or tagline of what your project does. This
3434
# corresponds to the "Summary" metadata field:

0 commit comments

Comments
 (0)