因此,我正在迭代超过 200 万个对象:-
conn = boto.connect_s3('xxx','xxx')
bucket = conn.lookup('bucket_name')
for key in bucket.list():
somefunction(key.name)
假设它在第 100 万个对象处失败,我将如何从那时起恢复此操作?
我通过查看boto源弄清楚了。
def list(self, prefix='', delimiter='', marker='', headers=None):
将 key.name 传递给 marker 将允许您从该点恢复操作。
marker
使用该属性恢复请求的示例。
如果您想通过子树递归或有数百万个对象要爬过并且不希望它们在单个列表中,这也很有用。
marker = None
while True:
keys = bucket.get_all_keys(marker=marker)
last_key = None
for k in keys:
# TODO Do something with your keys!
last_key = k.name
if not keys.is_truncated:
break
marker = last_key