sharafetdinov42 commited on
Commit
d7e6665
·
verified ·
1 Parent(s): 2b0a51e
Files changed (1) hide show
  1. streamlit_app.py +28 -2
streamlit_app.py CHANGED
@@ -1,3 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import streamlit as st
2
 
3
  main_page = st.Page("main.py", title="Описание"
@@ -13,5 +41,3 @@ pg = st.navigation(
13
  st.set_page_config(page_title="Leaderboard", layout="wide", page_icon="🏆",
14
  )
15
  pg.run()
16
-
17
-
 
1
+ import os, time, pathlib, shutil
2
+
3
+ os.environ.setdefault("TMPDIR", "/tmp/streamlit_tmp")
4
+ tmpdir = pathlib.Path(os.environ["TMPDIR"])
5
+ tmpdir.mkdir(parents=True, exist_ok=True)
6
+
7
+ def prune_old_files(root: str, max_age_sec: int = 30 * 60):
8
+ now = time.time()
9
+ p = pathlib.Path(root)
10
+ if not p.exists():
11
+ return
12
+ for path in p.rglob("*"):
13
+ try:
14
+ if path.is_file() and (now - path.stat().st_mtime > max_age_sec):
15
+ path.unlink(missing_ok=True)
16
+ except Exception:
17
+ pass
18
+ for path in sorted(p.rglob("*"), reverse=True):
19
+ try:
20
+ if path.is_dir() and not any(path.iterdir()):
21
+ path.rmdir()
22
+ except Exception:
23
+ pass
24
+
25
+ prune_old_files(tmpdir.as_posix(), max_age_sec=30 * 60)
26
+
27
+ prune_old_files("/tmp", max_age_sec=60 * 60)
28
+
29
  import streamlit as st
30
 
31
  main_page = st.Page("main.py", title="Описание"
 
41
  st.set_page_config(page_title="Leaderboard", layout="wide", page_icon="🏆",
42
  )
43
  pg.run()