Only retry for specific error codes

This commit is contained in:
Kovid Goyal 2022-03-09 08:40:36 +05:30
parent 29482963b7
commit 3e97ae74d6
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -346,13 +346,17 @@ class ConfigInterface:
def retry_on_fail(func, *args, count=10, sleep_time=0.2):
import time
ERROR_SHARING_VIOLATION = 32
ACCESS_DENIED = 5
for i in range(count):
try:
return func(*args)
except FileNotFoundError:
raise
except OSError:
if not iswindows or i > count - 2:
except OSError as e:
# Windows stupidly gives us an ACCESS_DENIED rather than a
# ERROR_SHARING_VIOLATION if the file is open
if not iswindows or i > count - 2 or e.winerror not in (ERROR_SHARING_VIOLATION, ACCESS_DENIED):
raise
# Try the operation repeatedly in case something like a virus
# scanner has opened one of the files (I love windows)