我希望能够以分布式方式在Python中处理位于S3存储桶中的大量XML文件夹。
因此,我首先使用boto3库定义了一个分页器,并设置(例如)每页100
个元素的页面大小(请参见文档)。
profile = boto3.Session()
client = profile.client('s3')
paginator = client.get_paginator('list_objects')
page_iterator = paginator.paginate(
Bucket='my-bucket',Prefix='my-prefix',
PaginationConfig={'PageSize': 100}
)
之后,通过使用concurrent.futures
包,我创建了一个线程池,其中有 10
个线程分别调用了my_process_method
方法:
def my_process_method(pages):
for page in pages['Contents']:
# ...process...
with concurrent.futures.ThreadPoolExecutor(10) as executor:
executor.map(my_process_method, page_iterator)
我想知道这个例子有没有一些缺点,例如并发的boto3
API调用可能会导致某些问题。