11"""Amazon S3 Describe Module (INTERNAL)."""
22
3+ import concurrent .futures
34import datetime
45import itertools
56import logging
89import boto3
910
1011from awswrangler import _utils
11- from awswrangler ._distributed import engine
12- from awswrangler ._threading import _get_executor
13- from awswrangler .distributed .ray import ray_get
1412from awswrangler .s3 import _fs
1513from awswrangler .s3 ._list import _path2list
1614
1715_logger : logging .Logger = logging .getLogger (__name__ )
1816
1917
20- @engine .dispatch_on_engine
2118def _describe_object (
22- boto3_session : boto3 .Session ,
2319 path : str ,
20+ boto3_session : boto3 .Session ,
2421 s3_additional_kwargs : Optional [Dict [str , Any ]],
2522 version_id : Optional [str ] = None ,
2623) -> Tuple [str , Dict [str , Any ]]:
@@ -43,6 +40,18 @@ def _describe_object(
4340 return path , desc
4441
4542
43+ def _describe_object_concurrent (
44+ path : str ,
45+ boto3_primitives : _utils .Boto3PrimitivesType ,
46+ s3_additional_kwargs : Optional [Dict [str , Any ]],
47+ version_id : Optional [str ] = None ,
48+ ) -> Tuple [str , Dict [str , Any ]]:
49+ boto3_session = _utils .boto3_from_primitives (primitives = boto3_primitives )
50+ return _describe_object (
51+ path = path , boto3_session = boto3_session , s3_additional_kwargs = s3_additional_kwargs , version_id = version_id
52+ )
53+
54+
4655def describe_objects (
4756 path : Union [str , List [str ]],
4857 version_id : Optional [Union [str , Dict [str , str ]]] = None ,
@@ -118,22 +127,41 @@ def describe_objects(
118127 last_modified_end = last_modified_end ,
119128 s3_additional_kwargs = s3_additional_kwargs ,
120129 )
121-
122130 if len (paths ) < 1 :
123131 return {}
124132 resp_list : List [Tuple [str , Dict [str , Any ]]]
125-
126- executor = _get_executor (use_threads = use_threads )
127- resp_list = ray_get (
128- executor .map (
129- _describe_object ,
130- boto3_session ,
131- paths ,
132- itertools .repeat (s3_additional_kwargs ),
133- [version_id .get (p ) if isinstance (version_id , dict ) else version_id for p in paths ],
134- )
135- )
136-
133+ if len (paths ) == 1 :
134+ resp_list = [
135+ _describe_object (
136+ path = paths [0 ],
137+ version_id = version_id .get (paths [0 ]) if isinstance (version_id , dict ) else version_id ,
138+ boto3_session = boto3_session ,
139+ s3_additional_kwargs = s3_additional_kwargs ,
140+ )
141+ ]
142+ elif use_threads is False :
143+ resp_list = [
144+ _describe_object (
145+ path = p ,
146+ version_id = version_id .get (p ) if isinstance (version_id , dict ) else version_id ,
147+ boto3_session = boto3_session ,
148+ s3_additional_kwargs = s3_additional_kwargs ,
149+ )
150+ for p in paths
151+ ]
152+ else :
153+ cpus : int = _utils .ensure_cpu_count (use_threads = use_threads )
154+ versions = [version_id .get (p ) if isinstance (version_id , dict ) else version_id for p in paths ]
155+ with concurrent .futures .ThreadPoolExecutor (max_workers = cpus ) as executor :
156+ resp_list = list (
157+ executor .map (
158+ _describe_object_concurrent ,
159+ paths ,
160+ versions ,
161+ itertools .repeat (_utils .boto3_to_primitives (boto3_session = boto3_session )),
162+ itertools .repeat (s3_additional_kwargs ),
163+ )
164+ )
137165 desc_dict : Dict [str , Dict [str , Any ]] = dict (resp_list )
138166 return desc_dict
139167
0 commit comments