mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Only retry for specific error codes
This commit is contained in:
parent
29482963b7
commit
3e97ae74d6
@ -346,13 +346,17 @@ class ConfigInterface:
|
|||||||
|
|
||||||
def retry_on_fail(func, *args, count=10, sleep_time=0.2):
|
def retry_on_fail(func, *args, count=10, sleep_time=0.2):
|
||||||
import time
|
import time
|
||||||
|
ERROR_SHARING_VIOLATION = 32
|
||||||
|
ACCESS_DENIED = 5
|
||||||
for i in range(count):
|
for i in range(count):
|
||||||
try:
|
try:
|
||||||
return func(*args)
|
return func(*args)
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
raise
|
raise
|
||||||
except OSError:
|
except OSError as e:
|
||||||
if not iswindows or i > count - 2:
|
# 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
|
raise
|
||||||
# Try the operation repeatedly in case something like a virus
|
# Try the operation repeatedly in case something like a virus
|
||||||
# scanner has opened one of the files (I love windows)
|
# scanner has opened one of the files (I love windows)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user