Skip to content

Commit 88d19ce

Browse files
sbryngelsonclaude
andcommitted
Retry delete_directory on Lustre ENOTEMPTY race
shutil.rmtree can fail with "Directory not empty" on networked filesystems (Lustre) due to metadata propagation delays. Retry up to 5 times with 1s backoff before raising. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 8022969 commit 88d19ce

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

toolchain/mfc/common.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import os, yaml, typing, shutil, subprocess, logging
1+
import os, yaml, typing, shutil, subprocess, logging, time
22

33
from os.path import join, abspath, normpath, dirname, realpath
44

@@ -122,8 +122,16 @@ def create_directory(dirpath: str) -> None:
122122

123123

124124
def delete_directory(dirpath: str) -> None:
125-
if os.path.isdir(dirpath):
126-
shutil.rmtree(dirpath)
125+
for attempt in range(5):
126+
if not os.path.isdir(dirpath):
127+
return
128+
try:
129+
shutil.rmtree(dirpath)
130+
return
131+
except OSError:
132+
if attempt == 4:
133+
raise
134+
time.sleep(1)
127135

128136

129137
def get_program_output(arguments: typing.List[str] = None, cwd=None):

0 commit comments

Comments
 (0)