Skip to content

Commit ef9e22b

Browse files
zoobaambv
andauthored
bpo-45055: Add retry when downloading externals on Windows (pythonGH-28399)
Co-authored-by: Łukasz Langa <[email protected]>
1 parent a856364 commit ef9e22b

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

PCbuild/get_external.py

+18-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import argparse
44
import os
55
import pathlib
6+
import sys
7+
import time
68
import zipfile
79
from urllib.request import urlretrieve
810

@@ -53,7 +55,22 @@ def main():
5355
verbose=args.verbose,
5456
)
5557
final_name = args.externals_dir / args.tag
56-
extract_zip(args.externals_dir, zip_path).replace(final_name)
58+
extracted = extract_zip(args.externals_dir, zip_path)
59+
for wait in [1, 2, 3, 5, 8, 0]:
60+
try:
61+
extracted.replace(final_name)
62+
break
63+
except PermissionError as ex:
64+
retry = f" Retrying in {wait}s..." if wait else ""
65+
print(f"Encountered permission error '{ex}'.{retry}", file=sys.stderr)
66+
time.sleep(wait)
67+
else:
68+
print(
69+
f"ERROR: Failed to extract {final_name}.",
70+
"You may need to restart your build",
71+
file=sys.stderr,
72+
)
73+
sys.exit(1)
5774

5875

5976
if __name__ == '__main__':

0 commit comments

Comments
 (0)