Schwachjam-Nachspiel: fortsetzbar (--fortsetzen) und am Mac lauffaehig

Der Vollnachspiel-Lauf wurde am 01.12. ~13:30 abgebrochen (rund 1.600 von
57.755 Anfragen je Arm). --fortsetzen ueberspringt Anfragen, die in der
Teildatei schon beantwortet sind, und haengt nur an; die Enddatei entsteht
per Temp-Datei und Umbenennen und nur, wenn sie alle Zeilen einer
vorhandenen enthaelt. Pfade per NACHSPIEL_LIVE / NACHSPIEL_DATEN, auf
POSIX nice 10 statt BelowNormal.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-12-01 14:19:51 +01:00
co-authored by Claude Opus 5.5
parent d8329c0f53
commit f4bdaca89b
+49 -11
View File
@@ -6,6 +6,10 @@ Mehrere Prozesse (je ein Stueck der Anfragen in Zeitfolge), BelowNormal, kein Fe
python -I -X utf8 nachspiel.py <exe> <anfragen.jsonl> <aus.jsonl> [--teile N] [--jede K] [--bis M] [--strasse S] [--ids datei] [SCHALTER=WERT ...]
anfragen.jsonl: faelle.jsonl (Feld q, seed) oder das rohe Schattenlog des Live-Baums (Feld q, seed, zeit >= 2026-11-24)
--jede K: jede K-te Anfrage; --bis M: nur die ersten M Anfragen (nach --jede)
--fortsetzen (nur mit --mische): setzt einen abgebrochenen Lauf fort. Anfragen, deren i schon in <aus>.teil steht, werden
uebersprungen; neue Zeilen werden nur angehaengt. Am Ende entsteht <aus> per Temp-Datei und Umbenennen aus der ganzen
Teildatei, und nur, wenn jede Zeile eines vorhandenen <aus> darin enthalten ist (nie Daten verlieren).
Pfade fuer andere Rechner (Mac): NACHSPIEL_LIVE (Live-Baum mit betrieb/kern_schalter.txt), NACHSPIEL_DATEN (Grundstrategie-Ordner).
"""
import json
import os
@@ -14,8 +18,9 @@ import sys
import threading
import time
LIVE = "D:/Projects/pokerfreak/.claude/worktrees/engine-lecks-angreifen-de7b88"
D = "D:/Projects/pokerfreak/daten/grundstrategie/motor"
LIVE = os.environ.get("NACHSPIEL_LIVE", "D:/Projects/pokerfreak/.claude/worktrees/engine-lecks-angreifen-de7b88")
D = os.environ.get("NACHSPIEL_DATEN", "D:/Projects/pokerfreak/daten/grundstrategie/motor")
FENSTERLOS_NIEDRIG = 0x4000 | 0x08000000 if os.name == "nt" else 0 # BelowNormal + kein Fenster (nur Windows)
TEIL = None
@@ -39,7 +44,7 @@ def starte(exe, extra):
env.update(extra)
return subprocess.Popen([exe, "dienst", "sechs100", D, "2000-600-400", "200", f"{D}/sechs100-v2.bin", "genau", f"hu={D}/hu100-v1.bin,{D}/hu200-v2.bin"],
stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.DEVNULL, text=True, encoding="utf-8", env=env,
creationflags=0x4000 | 0x08000000)
creationflags=FENSTERLOS_NIEDRIG, preexec_fn=None if os.name == "nt" else (lambda: os.nice(10)))
def teil(exe, extra, stueck, ausg, sperre):
@@ -70,11 +75,26 @@ def teil(exe, extra, stueck, ausg, sperre):
p.kill()
def erledigte(teil_pfad):
"""i aller Anfragen, die in der Teildatei schon eine Antwort ohne Fehler haben."""
if not os.path.exists(teil_pfad):
return set()
fertig = set()
for z in open(teil_pfad, encoding="utf-8"):
try:
x = json.loads(z)
except ValueError:
continue
if "i" in x and "fehler" not in x:
fertig.add(x["i"])
return fertig
def main():
arg = sys.argv[1:]
exe, ein, aus = arg[0], arg[1], arg[2]
teile, jede, bis, extra, mische = 4, 1, None, {}, None
strasse, ids = None, None
strasse, ids, fortsetzen = None, None, False
i = 3
while i < len(arg):
if arg[i] == "--teile":
@@ -87,12 +107,16 @@ def main():
strasse = arg[i + 1]; i += 2
elif arg[i] == "--ids":
ids = {int(t) for t in open(arg[i + 1], encoding="utf-8").read().split()}; i += 2
elif arg[i] == "--fortsetzen":
fortsetzen = True; i += 1
elif arg[i] == "--bis":
bis = int(arg[i + 1]); i += 2
else:
k, v = arg[i].split("=", 1)
extra[k] = v; i += 1
if os.path.exists(aus) and os.path.getsize(aus) > 0:
if fortsetzen and mische is None:
sys.exit("--fortsetzen nur mit --mische (feste Reihenfolge)")
if os.path.exists(aus) and os.path.getsize(aus) > 0 and not fortsetzen:
sys.exit("Ausgabe existiert: " + aus)
F = []
for nr, z in enumerate(open(ein, "rb")):
@@ -113,10 +137,15 @@ def main():
F = F[:bis]
if mische is not None:
global TEIL
stuecke = [F[k::teile] for k in range(teile)]
TEIL = aus + ".teil"
if os.path.exists(TEIL) and os.path.getsize(TEIL) > 0:
if fortsetzen:
fertig = erledigte(TEIL)
vorher = len(F)
F = [x for x in F if x[0] not in fertig]
print(f"fortsetzen: {vorher - len(F)} erledigt, {len(F)} offen", flush=True)
elif os.path.exists(TEIL) and os.path.getsize(TEIL) > 0:
sys.exit("Teildatei existiert: " + TEIL)
stuecke = [F[k::teile] for k in range(teile)]
else:
gr = (len(F) + teile - 1) // teile
stuecke = [F[k * gr:(k + 1) * gr] for k in range(teile)]
@@ -128,10 +157,19 @@ def main():
time.sleep(30)
print(f"{time.time() - t0:.0f}s: {sum(len(r) for r in res)}/{len(F)}", flush=True)
tmp = aus + ".tmp"
with open(tmp, "w", encoding="utf-8", newline="\n") as f:
for r in res:
for x in r:
f.write(json.dumps(x, ensure_ascii=False) + "\n")
if fortsetzen:
zeilen = open(TEIL, encoding="utf-8").read().splitlines()
if os.path.exists(aus):
fehlt = set(open(aus, encoding="utf-8").read().splitlines()) - set(zeilen)
if fehlt:
sys.exit(f"{aus} hat {len(fehlt)} Zeilen, die in {TEIL} fehlen: nicht ersetzt")
with open(tmp, "w", encoding="utf-8", newline="\n") as f:
f.write("".join(z + "\n" for z in zeilen))
else:
with open(tmp, "w", encoding="utf-8", newline="\n") as f:
for r in res:
for x in r:
f.write(json.dumps(x, ensure_ascii=False) + "\n")
os.replace(tmp, aus)
print("fertig", len(F), "Anfragen in", round(time.time() - t0), "s ->", aus)