diff --git a/live/cache.py b/live/cache.py index 5dbce6f7..39d61b94 100644 --- a/live/cache.py +++ b/live/cache.py @@ -64,7 +64,28 @@ def conv_cutoff(sizes, q=CONV_PCTILE): return s[f] if f + 1 >= len(s) else s[f] + (s[f + 1] - s[f]) * (k - f) _lock = threading.Lock() -_con = duckdb.connect(DB) + + +def _connect(db=None, tries=24, wait=15): + """duckdb is SINGLE-WRITER and this module connects at IMPORT time, so a + daily/nightly overlap used to raise straight out of `import cache` — + killing forward.py and, through nightly.sh's `set -e`, every grader + behind it (2026-07-27 and again 07-28: the graders silently never ran). + Wait the other writer out instead; 6 min covers a collect pass.""" + db = db or DB + for i in range(tries): + try: + return duckdb.connect(db) + except Exception as e: + if "lock" not in str(e).lower() or i == tries - 1: + raise + if i == 0: + print(f"[cache] {os.path.basename(db)} locked by another " + f"writer — waiting…", flush=True) + time.sleep(wait) + + +_con = _connect() _con.execute("""CREATE TABLE IF NOT EXISTS bets( wallet TEXT, cond TEXT, asset TEXT, won BOOLEAN, p DOUBLE, res_t BIGINT, size DOUBLE, src TEXT, ts BIGINT, resolved BOOLEAN)""")