Skip to content

Commit 124fa59

Browse files
authored
Reuse s3 client across threads for s3 range requests (#684)
1 parent 6699791 commit 124fa59

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

awswrangler/s3/_fs.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -104,15 +104,13 @@ def _fetch_range(
104104
range_values: Tuple[int, int],
105105
bucket: str,
106106
key: str,
107-
boto3_primitives: _utils.Boto3PrimitivesType,
107+
s3_client: boto3.client,
108108
boto3_kwargs: Dict[str, Any],
109109
) -> Tuple[int, bytes]:
110110
start, end = range_values
111111
_logger.debug("Fetching: s3://%s/%s - Range: %s-%s", bucket, key, start, end)
112-
boto3_session: boto3.Session = _utils.boto3_from_primitives(primitives=boto3_primitives)
113-
client: boto3.client = _utils.client(service_name="s3", session=boto3_session)
114112
resp: Dict[str, Any] = _utils.try_it(
115-
f=client.get_object,
113+
f=s3_client.get_object,
116114
ex=_S3_RETRYABLE_ERRORS,
117115
base=0.5,
118116
max_num_tries=6,
@@ -314,7 +312,7 @@ def _merge_range(ranges: List[Tuple[int, bytes]]) -> bytes:
314312

315313
def _fetch_range_proxy(self, start: int, end: int) -> bytes:
316314
_logger.debug("Fetching: s3://%s/%s - Range: %s-%s", self._bucket, self._key, start, end)
317-
boto3_primitives: _utils.Boto3PrimitivesType = _utils.boto3_to_primitives(boto3_session=self._boto3_session)
315+
s3_client: boto3.client = _utils.client(service_name="s3", session=self._boto3_session)
318316
boto3_kwargs: Dict[str, Any] = get_botocore_valid_kwargs(
319317
function_name="get_object", s3_additional_kwargs=self._s3_additional_kwargs
320318
)
@@ -325,7 +323,7 @@ def _fetch_range_proxy(self, start: int, end: int) -> bytes:
325323
range_values=(start, end),
326324
bucket=self._bucket,
327325
key=self._key,
328-
boto3_primitives=boto3_primitives,
326+
s3_client=s3_client,
329327
boto3_kwargs=boto3_kwargs,
330328
)[1]
331329
sizes: Tuple[int, ...] = _utils.get_even_chunks_sizes(
@@ -344,7 +342,7 @@ def _fetch_range_proxy(self, start: int, end: int) -> bytes:
344342
ranges,
345343
itertools.repeat(self._bucket),
346344
itertools.repeat(self._key),
347-
itertools.repeat(boto3_primitives),
345+
itertools.repeat(s3_client),
348346
itertools.repeat(boto3_kwargs),
349347
)
350348
),

0 commit comments

Comments
 (0)