Artificial-superintelligence commited on
Commit
0f94234
·
verified ·
1 Parent(s): e4a160c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -8
app.py CHANGED
@@ -4,6 +4,7 @@ import os
4
  import shutil
5
  import uuid
6
  from pathlib import Path
 
7
 
8
  # Generate a unique workspace for the user
9
  session_id = str(uuid.uuid4())
@@ -18,6 +19,12 @@ def run_shell_command(command):
18
  except subprocess.CalledProcessError as e:
19
  return f"Error: {e.output}"
20
 
 
 
 
 
 
 
21
  # Custom CSS for styling
22
  st.markdown(
23
  """
@@ -87,14 +94,6 @@ if st.button("Export Code"):
87
  else:
88
  st.error("No code to export!")
89
 
90
- # Cleanup workspace on session end
91
- def cleanup_workspace():
92
- if os.path.exists(workspace_dir):
93
- shutil.rmtree(workspace_dir)
94
-
95
- # Streamlit lifecycle hook for cleanup
96
- st.on_event("teardown", cleanup_workspace)
97
-
98
  st.markdown("---")
99
  st.info(
100
  """
 
4
  import shutil
5
  import uuid
6
  from pathlib import Path
7
+ import atexit
8
 
9
  # Generate a unique workspace for the user
10
  session_id = str(uuid.uuid4())
 
19
  except subprocess.CalledProcessError as e:
20
  return f"Error: {e.output}"
21
 
22
+ # Cleanup workspace when the script exits
23
+ def cleanup_workspace():
24
+ if os.path.exists(workspace_dir):
25
+ shutil.rmtree(workspace_dir)
26
+ atexit.register(cleanup_workspace)
27
+
28
  # Custom CSS for styling
29
  st.markdown(
30
  """
 
94
  else:
95
  st.error("No code to export!")
96
 
 
 
 
 
 
 
 
 
97
  st.markdown("---")
98
  st.info(
99
  """