File tree 2 files changed +21
-1
lines changed
2 files changed +21
-1
lines changed Original file line number Diff line number Diff line change 9
9
import subprocess
10
10
import sys
11
11
import textwrap
12
+ import time
12
13
import tomllib
13
14
import warnings
14
15
import zipfile
@@ -493,3 +494,21 @@ def download_and_unpack_archive(
493
494
# https://github.com/python/cpython/issues/112760
494
495
warnings .simplefilter ("ignore" )
495
496
shutil .unpack_archive (str (f_path ), path )
497
+
498
+
499
+ def retrying_rmtree (d ):
500
+ """Sometimes rmtree fails with OSError: Directory not empty
501
+
502
+ Try again a few times if this happens.
503
+ See: https://github.com/python/cpython/issues/128076
504
+ """
505
+ for _ in range (3 ):
506
+ try :
507
+ return shutil .rmtree (d )
508
+ except OSError as e :
509
+ if e .strerror == "Directory not empty" :
510
+ # wait a bit and try again up to 3 tries
511
+ time .sleep (0.01 )
512
+ else :
513
+ raise
514
+ raise RuntimeError (f"shutil.rmtree('{ d } ') failed with ENOTEMPTY three times" )
Original file line number Diff line number Diff line change 37
37
make_zip_archive ,
38
38
modify_wheel ,
39
39
retag_wheel ,
40
+ retrying_rmtree ,
40
41
)
41
42
from pyodide_build .logger import logger
42
43
from pyodide_build .recipe .bash_runner import (
@@ -243,7 +244,7 @@ def _prepare_source(self) -> None:
243
244
244
245
# clear the build directory
245
246
if self .build_dir .resolve ().is_dir ():
246
- shutil . rmtree (self .build_dir )
247
+ retrying_rmtree (self .build_dir )
247
248
248
249
self .build_dir .mkdir (parents = True , exist_ok = True )
249
250
You can’t perform that action at this time.
0 commit comments