Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/amazon-s3/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x 如何使用asyncio在s3 bucket上下载文件_Python 3.x_Amazon S3_Boto_Boto3 - Fatal编程技术网

Python 3.x 如何使用asyncio在s3 bucket上下载文件

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

我使用以下代码下载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_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支持。如果您愿意修改您的代码以供使用,那么这将是一个解决方案