hf-mount-lock-repro / hammer.py
XciD's picture
XciD HF Staff
Upload folder using huggingface_hub
e01e433 verified
Raw
History Blame Contribute Delete
1.53 kB
import os, sys, time, threading, traceback, sqlite3
from pathlib import Path
os.environ.setdefault("SYSTEM", "spaces")
from trackio.sqlite_storage import SQLiteStorage
DB_DIR = Path(os.environ["TRACKIO_DIR"]); DB_DIR.mkdir(parents=True, exist_ok=True)
PROJECT = "bugtest"; N_THREADS = 8; N_LOGS = 200
errors = []; elock = threading.Lock(); done = [0]*N_THREADS
def writer(tid):
for i in range(N_LOGS):
try:
SQLiteStorage.log(project=PROJECT, run=f"run-{tid}", metrics={"x":i,"thread":tid}, step=i)
done[tid] += 1
except Exception as e:
with elock: errors.append((tid,i,repr(e)))
t0 = time.time()
threads = [threading.Thread(target=writer, args=(i,)) for i in range(N_THREADS)]
for t in threads: t.start()
for t in threads: t.join()
dt = time.time() - t0
print(f"dt={dt:.2f}s done={done} errors={len(errors)}")
for e in errors[:5]: print(f" T{e[0]}@{e[1]}: {e[2]}")
dbp = SQLiteStorage.get_project_db_path(PROJECT)
print(f"db_path={dbp} size={os.path.getsize(dbp)}")
c = sqlite3.connect(str(dbp))
integ = [r[0] for r in c.execute("PRAGMA integrity_check").fetchall()]
print(f"integrity: {integ}")
for run, n in c.execute("SELECT run_name, COUNT(*) FROM metrics GROUP BY run_name ORDER BY run_name").fetchall():
print(f" {run}: {n} rows")
(total,) = c.execute("SELECT COUNT(*) FROM metrics").fetchone()
exp = N_THREADS * N_LOGS
print(f"total_rows={total} expected={exp}")
ok = not errors and total == exp and integ == ["ok"]
print(f"RESULT: {'PASS' if ok else 'FAIL'}")