mirror of
https://github.com/ytdl-org/youtube-dl
synced 2024-11-30 19:02:55 +01:00
Retry loop with itertools
This commit is contained in:
parent
f7173cca4d
commit
2bd001fa8c
@ -20,6 +20,7 @@ from test.helper import (
|
|||||||
|
|
||||||
|
|
||||||
import hashlib
|
import hashlib
|
||||||
|
import itertools
|
||||||
import json
|
import json
|
||||||
import socket
|
import socket
|
||||||
import re
|
import re
|
||||||
@ -175,8 +176,7 @@ def generator(test_case, tname):
|
|||||||
|
|
||||||
try_rm_tcs_files()
|
try_rm_tcs_files()
|
||||||
try:
|
try:
|
||||||
try_num = 1
|
for try_num in itertools.count(1):
|
||||||
while True:
|
|
||||||
try:
|
try:
|
||||||
# We're not using .download here since that is just a shim
|
# We're not using .download here since that is just a shim
|
||||||
# for outside error handling, and returns the exit code
|
# for outside error handling, and returns the exit code
|
||||||
@ -185,7 +185,7 @@ def generator(test_case, tname):
|
|||||||
test_case['url'],
|
test_case['url'],
|
||||||
force_generic_extractor=params.get('force_generic_extractor', False))
|
force_generic_extractor=params.get('force_generic_extractor', False))
|
||||||
except (DownloadError, ExtractorError) as err:
|
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):
|
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))
|
msg = getattr(err, 'msg', error_to_compat_str(err))
|
||||||
err.msg = '%s (%s)' % (msg, tname, )
|
err.msg = '%s (%s)' % (msg, tname, )
|
||||||
@ -196,8 +196,6 @@ def generator(test_case, tname):
|
|||||||
return
|
return
|
||||||
|
|
||||||
print('Retrying: {0} failed tries\n\n##########\n\n'.format(try_num))
|
print('Retrying: {0} failed tries\n\n##########\n\n'.format(try_num))
|
||||||
|
|
||||||
try_num += 1
|
|
||||||
else:
|
else:
|
||||||
break
|
break
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user