Skip to content

Commit 68577fe

Browse files
fix: fix file locking error when removing cache folder (#162)
* fix: fix cache error * Update webui/app.py Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> * Update webui/utils/cache.py Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> * fix: fix lint error * fix: fix lint error --------- Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
1 parent b8cb9bb commit 68577fe

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

webui/app.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import json
22
import os
33
import sys
4+
import gc
45
import tempfile
56
from importlib.resources import files
67

@@ -178,6 +179,7 @@ def run_graphgen(params: WebuiParams, progress=gr.Progress()):
178179
"nodes": nodes,
179180
}
180181

182+
engine = None
181183
try:
182184
# 4. Initialize and Run Engine
183185
engine = Engine(config, operators)
@@ -214,6 +216,10 @@ def run_graphgen(params: WebuiParams, progress=gr.Progress()):
214216
raise gr.Error(f"Error occurred: {str(e)}")
215217

216218
finally:
219+
if engine:
220+
del engine
221+
gc.collect()
222+
217223
# Clean up workspace
218224
cleanup_workspace(working_dir) # Optional: keep for debugging or enable
219225

webui/utils/cache.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import os
22
import shutil
3+
import stat
4+
import time
35
import uuid
46

57

@@ -17,6 +19,14 @@ def setup_workspace(folder):
1719
return log_file, working_dir
1820

1921

20-
def cleanup_workspace(folder):
21-
if os.path.exists(folder):
22-
shutil.rmtree(folder)
22+
def cleanup_workspace(working_dir):
23+
if not os.path.exists(working_dir):
24+
return
25+
st = os.stat(working_dir)
26+
os.chmod(working_dir, st.st_mode | stat.S_IWRITE)
27+
28+
time.sleep(0.5)
29+
try:
30+
shutil.rmtree(working_dir)
31+
except Exception:
32+
pass

0 commit comments

Comments
 (0)