Skip to content

Commit

Permalink
Retry loop with itertools
Browse files Browse the repository at this point in the history
  • Loading branch information
dirkf committed Feb 21, 2024
1 parent f7173cc commit 2bd001f
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions test/test_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@


import hashlib
import itertools
import json
import socket
import re
Expand Down Expand Up @@ -175,8 +176,7 @@ def try_rm_tcs_files(tcs=None):

try_rm_tcs_files()
try:
try_num = 1
while True:
for try_num in itertools.count(1):
try:
# We're not using .download here since that is just a shim
# for outside error handling, and returns the exit code
Expand All @@ -185,7 +185,7 @@ def try_rm_tcs_files(tcs=None):
test_case['url'],
force_generic_extractor=params.get('force_generic_extractor', False))
except (DownloadError, ExtractorError) as err:
# Check if the exception is not a network related one
# Retry, or raise if the exception is not network-related
if not err.exc_info[0] in (compat_urllib_error.URLError, socket.timeout, UnavailableVideoError, compat_http_client.BadStatusLine) or (err.exc_info[0] == compat_HTTPError and err.exc_info[1].code == 503):
msg = getattr(err, 'msg', error_to_compat_str(err))
err.msg = '%s (%s)' % (msg, tname, )
Expand All @@ -196,8 +196,6 @@ def try_rm_tcs_files(tcs=None):
return

print('Retrying: {0} failed tries\n\n##########\n\n'.format(try_num))

try_num += 1
else:
break

Expand Down

0 comments on commit 2bd001f

Please sign in to comment.