Python 3.x azure容器\u客户端删除\u blob导致oom
我正在使用Azure blob SDK python版本。以下是我如何删除blob的方法:Python 3.x azure容器\u客户端删除\u blob导致oom,python-3.x,azure,azure-storage-blobs,Python 3.x,Azure,Azure Storage Blobs,我正在使用Azure blob SDK python版本。以下是我如何删除blob的方法: blobs = container_client.list_blobs(name_starts_with="myprefix") container_client.delete_blobs(*blobs) 如果blob此处返回大量blob对象,则上述代码将崩溃。 这里的标准做法是什么?是否有其他方法进行批量删除 更新: 回复@Ivan Yang: 这与您的解决方案略有不同。我运行了
blobs = container_client.list_blobs(name_starts_with="myprefix")
container_client.delete_blobs(*blobs)
如果blob
此处返回大量blob对象,则上述代码将崩溃。
这里的标准做法是什么?是否有其他方法进行批量删除
更新:
回复@Ivan Yang:
这与您的解决方案略有不同。我运行了它,但出错了
批处理操作中存在部分故障
您最好使用
delete\u blobs
方法指定要删除的blob数量。这样就更容易调试了
作为一种解决方法,您可以每次获取一定数量(如10个blob)的blob,然后删除,直到继续标记
为空
以下是示例代码:
#define a continuation token
continuation_token = None
while True:
#fetch 10 blobs each time
blob_list = container_client.list_blobs(name_starts_with="xxx",results_per_page=10).by_page(continuation_token=continuation_token)
list_segment=[blob.name for blob in list(next(blob_list))]
container_client.delete_blobs(*list_segment)
continuation_token = blob_list.continuation_token
if not continuation_token:
break
您还记得返回了多少个导致问题的blob吗?请提供一个完整的示例,它将更容易复制和修复。它是190个blob,我发现每个blob都是一个对象而不是一个字符串。这就解释了为什么它会爆炸内存。很好的解决方案。另一个疑问是,为什么我们不能先得到所有斑点,然后批量删除大小为10的斑点?没关系。你的解决方案非常好!谢谢
#define a continuation token
continuation_token = None
while True:
#fetch 10 blobs each time
blob_list = container_client.list_blobs(name_starts_with="xxx",results_per_page=10).by_page(continuation_token=continuation_token)
list_segment=[blob.name for blob in list(next(blob_list))]
container_client.delete_blobs(*list_segment)
continuation_token = blob_list.continuation_token
if not continuation_token:
break