Python TQDM - 在失败的情况下获取最后一次迭代以重试循环

时间:2017-02-15 11:35:45

标签: python tqdm

有没有办法在发生故障的情况下使用Python的tqdm模块进行最后一次迭代,例如异常?我在文档或Google上没有找到任何内容。

我想得到最后一次迭代,所以我可以从发生异常的地方开始循环(在我的情况下是超时错误)。

我虽然有这样的事情:

def loop_and_call_external_service(list, start_at=0):
    if start_at > 0:
        # cut the list using start_at index

    for i in tqdm(list):
       call_a_service_that_might_timeout(list.id)

retry_attempts = 0

try:
    loop_and_call_external_service(list, 0)
except SomeService.TimeoutException:
    if retry_attempts <= 3:
        retry_attempts += 1
        last_index = tqdm._last_iteration_pointer
        loop_and_call_external_service(list, last_index)
    else:
        exit()
exception AnythingElse:
    exit()
  • 不是真正的代码,只是让你们能够理解我想要做的事情。

0 个答案:

没有答案
相关问题