Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions webui/app.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import json
import os
import sys
import gc
import tempfile
from importlib.resources import files

Expand Down Expand Up @@ -178,6 +179,7 @@ def run_graphgen(params: WebuiParams, progress=gr.Progress()):
"nodes": nodes,
}

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

finally:
if engine:
del engine
gc.collect()

# Clean up workspace
cleanup_workspace(working_dir) # Optional: keep for debugging or enable

Expand Down
25 changes: 20 additions & 5 deletions webui/utils/cache.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import os
import shutil
import time
import uuid
import shutil
import os
import sys
import stat


def setup_workspace(folder):
Expand All @@ -17,6 +20,18 @@ def setup_workspace(folder):
return log_file, working_dir


def cleanup_workspace(folder):
if os.path.exists(folder):
shutil.rmtree(folder)
def on_rm_error(func, path, exc_info):
st = os.stat(path)
os.chmod(path, st.st_mode | stat.S_IWRITE)

time.sleep(0.5)
try:
func(path)
except Exception:
pass
Comment on lines +30 to +31
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Silently swallowing exceptions with except Exception: pass can hide underlying issues and make debugging difficult. If the cleanup consistently fails for some reason, you would have no way of knowing, and temporary files could accumulate. Consider logging the exception here, even if you don't re-raise it, so that persistent problems can be identified.


def cleanup_workspace(working_dir):
if sys.version_info >= (3, 12):
shutil.rmtree(working_dir, onexc=on_rm_error)
else:
shutil.rmtree(working_dir, onerror=on_rm_error)
Loading