请找到代码段 我需要访问S3中的zip文件并访问zip文件中的文件以进行进一步处理
代码段
问题:内存泄漏
s3_resource = boto3.resource('s3',
aws_access_key_id = 'XXXXXXX',
aws_secret_access_key = 'XXXXX')
file = s3_resource.Object('xxxxxx',filePath).get()
with io.BytesIO(file['Body'].read()) as t:
t.seek(0)
with ZipFile(t, 'r') as myzip:
问题:进程无法访问该文件,因为它正由另一个进程使用:(在行文件= s3.download_file(' bucket',' filename', f.name)
f = tempfile.TemporaryFile(delete=False)
print(f)
s3 = boto3.client('s3', aws_access_key_id = 'xxxxx',
aws_secret_access_key = 'jxxx')
file=s3.download_file('bucket','filename',
f.name)
with ZipFile(f.name, 'r') as myzip:
print('done')
请让我知道处理此问题的有效方法