← back to Designer Wallcoverings
enrich-full.py: per-output-file flock guard to prevent stacked duplicate workers (Mac2 near-freeze 2026-07-01)
92c43de8b74ff816df3469cf054b926d08702f6c · 2026-07-01 10:46:49 -0700 · Steve
Files touched
M onboarding/sangetsu-lilycolor/scripts/enrich-full.py
Diff
commit 92c43de8b74ff816df3469cf054b926d08702f6c
Author: Steve <steve@designerwallcoverings.com>
Date: Wed Jul 1 10:46:49 2026 -0700
enrich-full.py: per-output-file flock guard to prevent stacked duplicate workers (Mac2 near-freeze 2026-07-01)
---
onboarding/sangetsu-lilycolor/scripts/enrich-full.py | 18 +++++++++++++++++-
1 file changed, 17 insertions(+), 1 deletion(-)
diff --git a/onboarding/sangetsu-lilycolor/scripts/enrich-full.py b/onboarding/sangetsu-lilycolor/scripts/enrich-full.py
index 7f22c090..08460e90 100644
--- a/onboarding/sangetsu-lilycolor/scripts/enrich-full.py
+++ b/onboarding/sangetsu-lilycolor/scripts/enrich-full.py
@@ -20,7 +20,7 @@ imageType, description, _provider, _cost, wall_s.
Usage: enrich-full.py [out_jsonl]
out_jsonl defaults to staging/enrichment-full-063026A.jsonl
"""
-import sys, os, json, time, subprocess, urllib.request
+import sys, os, json, time, subprocess, urllib.request, fcntl
HERE = os.path.dirname(os.path.abspath(__file__))
PROJ = os.path.dirname(HERE)
@@ -198,6 +198,22 @@ def main():
out_path = sys.argv[1] if len(sys.argv) > 1 else DEFAULT_OUT
os.makedirs(os.path.dirname(out_path), exist_ok=True)
+ # --- single-instance guard (per output file) -------------------------------
+ # A second worker targeting the SAME shard file refuses to start, instead of
+ # stacking. On 2026-07-01, re-invoking the launcher stacked 5 orphaned
+ # enrich-full.py procs on shard0/shard1 that thrashed Mac2 swap to a
+ # near-freeze. Distinct shard files (shard0/shard1/sweep) still run in
+ # parallel because each gets its own lock. Lock releases on process exit.
+ _lock_fh = open(out_path + ".lock", "w")
+ try:
+ fcntl.flock(_lock_fh, fcntl.LOCK_EX | fcntl.LOCK_NB)
+ except OSError:
+ print(f"[guard] another enrich-full.py is already running for "
+ f"{os.path.basename(out_path)} — exiting without stacking.", flush=True)
+ sys.exit(0)
+ _lock_fh.write(str(os.getpid()) + "\n"); _lock_fh.flush()
+ globals()["_ENRICH_LOCK_FH"] = _lock_fh # keep ref alive so lock persists
+
all_items = discover_skus()
total = len(all_items)
done = load_done(out_path)
← 7c09908d auto-save: 2026-07-01T10:41:35 (5 files) — pending-approval/
·
back to Designer Wallcoverings
·
auto-save: 2026-07-01T11:11:52 (8 files) — DW-Programming/Im d55bd8f6 →