Python 3.x 如何使用asyncio在s3 bucket上下载文件
我使用以下代码下载s3存储桶中的所有文件:Python 3.x 如何使用asyncio在s3 bucket上下载文件,python-3.x,amazon-s3,boto,boto3,Python 3.x,Amazon S3,Boto,Boto3,我使用以下代码下载s3存储桶中的所有文件: def main(bucket_name, destination_dir): bucket = boto3.resource('s3').Bucket(bucket_name) for obj in bucket.objects.all(): if obj.key.endswith('/'): continue destination = '%s/%s' % (bucket_na
def main(bucket_name, destination_dir):
bucket = boto3.resource('s3').Bucket(bucket_name)
for obj in bucket.objects.all():
if obj.key.endswith('/'):
continue
destination = '%s/%s' % (bucket_name, obj.key)
if not os.path.exists(destination):
os.makedirs(os.path.dirname(destination), exist_ok=True)
bucket.download_file(obj.key, destination)
如果可能的话,我想知道如何使它异步
提前感谢您。开箱即用,boto3不支持异步IO。在这方面有一个开放的解决方案;它们可能适用于您的用例,也可能不适用于您的用例 使用aiohttp为botocore库提供异步IO支持。如果您愿意修改您的代码以供使用,那么这将是一个解决方案