Files
mmintelandClaude Fable 5.2 4c818c0542 Nachtlauf: Speicher-Regel (hoechstens 4 Motor-Prozesse am Mac, je ~10 GB), Werkzeug motorplatz.py
Um 23:40 liefen neun Motor-Prozesse und ein Training auf 64 GB: 39 GB
Auslagerung, Last ueber 300. Das Training ist am Sicherungspunkt beendet.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-12-01 23:43:51 +01:00

77 lines
2.7 KiB
Python

#!/usr/bin/env python3
"""Motorplatz: begrenzt, wie viele Motor-Dienst-Prozesse gleichzeitig auf DIESEM Rechner laufen (jeder laedt die Grundstrategie, ~10 GB).
python3 werkzeuge/motorplatz.py [--plaetze 4] -- <befehl mit genau EINEM Motor-Prozess>
Wartet (ohne CPU), bis einer der Plaetze frei ist, haelt ihn fuer die Dauer des Befehls und gibt ihn danach frei - auch bei Abbruch,
weil die Sperre am Dateideskriptor haengt (flock). Befehle, die selbst mehrere Motor-Prozesse starten (z. B. nachspiel.py --teile 3),
muessen auf --teile 1 gestellt und mehrfach mit je eigenem Platz gestartet werden. Stand der Plaetze: `motorplatz.py --stand`.
Am 01.12.2026 liefen am Mac (64 GB) neun Motor-Prozesse und ein Training gleichzeitig: 39 GB Auslagerung, Last 324, alles stand.
"""
import fcntl
import os
import subprocess
import sys
import time
ORDNER = os.environ.get("MOTORPLATZ_ORDNER", "/Volumes/Alpha SSD/pokerfreak-daten/pruefstand/MOTORPLATZ")
PLAETZE = 4
def belegt(pfad):
"""True, wenn der Platz gerade gehalten wird (ohne ihn zu nehmen)."""
with open(pfad, "a+") as f:
try:
fcntl.flock(f, fcntl.LOCK_EX | fcntl.LOCK_NB)
except OSError:
return True
fcntl.flock(f, fcntl.LOCK_UN)
return False
def nimm(plaetze, warte_s=5.0):
"""Blockiert, bis ein Platz frei ist; gibt (offene Datei, Nummer) zurueck. Die Datei offen halten = Platz halten."""
os.makedirs(ORDNER, exist_ok=True)
while True:
for i in range(plaetze):
f = open(os.path.join(ORDNER, f"platz{i}.lock"), "a+")
try:
fcntl.flock(f, fcntl.LOCK_EX | fcntl.LOCK_NB)
except OSError:
f.close()
continue
f.seek(0)
f.truncate()
f.write(f"{os.getpid()} {time.strftime('%H:%M:%S')} {' '.join(sys.argv[1:])[:200]}\n")
f.flush()
return f, i
time.sleep(warte_s)
def main():
arg = sys.argv[1:]
plaetze = PLAETZE
if "--plaetze" in arg:
i = arg.index("--plaetze")
plaetze = int(arg[i + 1])
del arg[i:i + 2]
if arg[:1] == ["--stand"]:
os.makedirs(ORDNER, exist_ok=True)
for i in range(plaetze):
p = os.path.join(ORDNER, f"platz{i}.lock")
zeile = open(p).read().strip() if os.path.exists(p) else ""
print(f"Platz {i}: {'belegt ' + zeile if os.path.exists(p) and belegt(p) else 'frei'}")
return 0
if arg[:1] != ["--"] or len(arg) < 2:
print(__doc__)
return 2
halter, nr = nimm(plaetze)
try:
return subprocess.call(arg[1:])
finally:
halter.close()
if __name__ == "__main__":
sys.exit(main())