Starter: Spielbetrieb automatisch erkennen, Budget 2/2, Laeufe anhalten statt toeten

Laeufer-Sperre (PID lebt) oder runner.py --act = Spiel: wirksames Budget 2/2 unabhaengig von
GRENZE.txt, Laeufe ueber Budget per NtSuspendProcess angehalten, nach Spielende fortgesetzt.
Zustand in BUDGET_JETZT.txt, Wechsel in starter.log. Test mit Attrappen-PID per
POKERBENCH_SPIELSPERRE.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-16 13:37:26 +01:00
co-authored by Claude Opus 5.5
parent 2ce79281ac
commit a6fbd703be
2 changed files with 130 additions and 8 deletions
+8
View File
@@ -260,3 +260,11 @@ Ersparnis (Deals bis zum Urteil, auf den echten Armen): referenz-reststack 50 %,
reraise-live-leiter 25 %, reraise-live-micro 16 %, micro-mdf/md 6-7 %, klare Verlierer und offene Arme 0 %
(dort greift der Verlierer-Stopp). LBR bei gleichen Armen: Urteil nach 55-57 % der Haende; ist der Arm wahr um
2,8 se schlechter, sagt der Stopp in 10 % NICHT-SCHLECHTER (das volle Tor laesst 20 % durch).
**Spielbetrieb automatisch** (gleicher Starter): alle 10 s Laeufer-Sperre `scratch\laeufer.pid` im Live-Baum
(PID lebt, Pruefung wie `sperre._lebt_windows`) oder ein python mit `runner.py --act` = Spiel. Dann 2/2 ohne
Ruecksicht auf GRENZE.txt: Laeufe ueber dem Budget per NtSuspendProcess angehalten, neue mit 2 Threads,
nach Spielende NtResumeProcess. Zustand in `messung_engine/BUDGET_JETZT.txt`, Wechsel in starter.log.
Angehaltene Laeufe loesen keine 60-min-Warnung aus. Die `--act`-Suche kostet ~0,8 s je Pruefung (WMI).
Test mit Attrappen-PID (`POKERBENCH_SPIELSPERRE`, `POKERBENCH_SPIEL_ACT=0`): zwei 4-Thread-Laeufe 30 s
angehalten (Herzschlag-Luecke 31 s), ein dritter lief mit 2 Threads, danach alle weiter.
+122 -8
View File
@@ -21,6 +21,15 @@
# Fenster) nach cpu.log. Ist 60 Minuten lang bei keinem laufenden Lauf etwas fertig geworden (keine
# Ausgabe-Datei, kein Log gewachsen, kein Lauf beendet), steht "WARNUNG ..." in starter.log und cpu.log
# (stuendlich wiederholt, solange es anhaelt).
# SPIELBETRIEB (16.11.): alle 10 s wird geprueft, ob gespielt wird: Laeufer-Sperre scratch\laeufer.pid
# (betrieb/sperre.py) im Live-Baum existiert und ihre PID lebt, oder ein python-Prozess mit runner.py --act
# laeuft. Dann gilt 2/2 (threads=2, je_lauf=2), egal was in GRENZE.txt steht: Laeufe ueber dem Budget werden
# angehalten (NtSuspendProcess, nicht beendet), neue starten mit 2 Threads; nach Spielende laufen sie weiter
# (NtResumeProcess) und GRENZE.txt gilt wieder. Wechsel stehen in starter.log, der wirksame Zustand in
# BUDGET_JETZT.txt (fuer Laeufe ausserhalb der Schlange: dort nachsehen). Ein Neustart setzt alle
# uebernommenen Laeufe erst fort und haelt sie bei Spiel neu an.
# Test ohne echten Laeufer: POKERBENCH_SPIELSPERRE=<Pfad einer Test-Sperre> (Datei mit einer PID),
# POKERBENCH_SPIEL_ACT=0 schaltet die Suche nach runner.py --act ab.
$ErrorActionPreference = 'Continue'
$D = Split-Path -Parent $MyInvocation.MyCommand.Path
(Get-Process -Id $PID).PriorityClass = 'Idle'
@@ -28,7 +37,7 @@ $PID | Set-Content "$D\STARTER.pid"
New-Item -ItemType Directory -Force "$D\logs" | Out-Null
if (-not (Test-Path "$D\erledigt.txt")) { New-Item -ItemType File "$D\erledigt.txt" | Out-Null }
function Grenze {
function GrenzeDatei {
$g = @{ threads = 16; je_lauf = 8 }
if (Test-Path "$D\GRENZE.txt") {
Get-Content "$D\GRENZE.txt" | ForEach-Object {
@@ -38,6 +47,106 @@ function Grenze {
$g
}
# Wirksames Budget: bei Spielbetrieb 2/2, sonst GRENZE.txt.
function Grenze {
if ($script:spiel) { return @{ threads = 2; je_lauf = 2 } }
GrenzeDatei
}
if (-not ('PbProz' -as [type])) {
Add-Type -TypeDefinition @'
using System;
using System.Runtime.InteropServices;
public static class PbProz {
[DllImport("kernel32.dll", SetLastError = true)] static extern IntPtr OpenProcess(uint zugriff, bool erben, int pid);
[DllImport("kernel32.dll")] static extern bool CloseHandle(IntPtr h);
[DllImport("kernel32.dll")] static extern bool GetExitCodeProcess(IntPtr h, out uint code);
[DllImport("ntdll.dll")] static extern int NtSuspendProcess(IntPtr h);
[DllImport("ntdll.dll")] static extern int NtResumeProcess(IntPtr h);
// wie betrieb/sperre._lebt_windows: Zugriff verweigert = es gibt ihn
public static bool Lebt(int pid) {
if (pid <= 0) return false;
IntPtr h = OpenProcess(0x1000, false, pid);
if (h == IntPtr.Zero) return Marshal.GetLastWin32Error() == 5;
try { uint c; return GetExitCodeProcess(h, out c) && c == 259; } finally { CloseHandle(h); }
}
static int Mach(int pid, bool anhalten) {
IntPtr h = OpenProcess(0x0800, false, pid); // PROCESS_SUSPEND_RESUME
if (h == IntPtr.Zero) return -1;
try { return anhalten ? NtSuspendProcess(h) : NtResumeProcess(h); } finally { CloseHandle(h); }
}
public static int Anhalten(int pid) { return Mach(pid, true); }
public static int Fortsetzen(int pid) { return Mach(pid, false); }
}
'@
}
$SPIELSPERRE = if ($env:POKERBENCH_SPIELSPERRE) { $env:POKERBENCH_SPIELSPERRE } else {
'D:\Projects\pokerfreak\.claude\worktrees\engine-lecks-angreifen-de7b88\scratch\laeufer.pid' }
$spiel = $null; $budget_zeile = $null
# Grund, warum gespielt wird ("sperre pid=..." / "runner --act pid=..."), sonst $null.
function Spiel {
if (Test-Path -LiteralPath $SPIELSPERRE) {
$n = 0
$txt = Get-Content -LiteralPath $SPIELSPERRE -Raw -ErrorAction SilentlyContinue
if ($txt -and [int]::TryParse($txt.Trim(), [ref]$n) -and [PbProz]::Lebt($n)) { return "sperre pid=$n" }
}
if ($env:POKERBENCH_SPIEL_ACT -ne '0') {
$r = Get-CimInstance Win32_Process -Filter "Name = 'python.exe' OR Name = 'pythonw.exe' OR Name = 'python3.exe'" -ErrorAction SilentlyContinue |
Where-Object { $_.CommandLine -and $_.CommandLine -match 'runner\.py' -and $_.CommandLine -match '--act\b' } |
Select-Object -First 1
if ($r) { return "runner --act pid=$($r.ProcessId)" }
}
$null
}
# Bei Spiel: Laeufe ueber 2 Threads anhalten (laufende behalten Vorrang, dann die kleinsten), passende
# angehaltene fortsetzen. Nach Spielende alle fortsetzen.
function Spielbudget {
$grund = Spiel
if ($grund -and -not $script:spiel) {
"spiel an ($grund): Budget 2/2 $(Get-Date -Format s)" | Add-Content "$D\starter.log"
}
if (-not $grund -and $script:spiel) {
foreach ($id in @($laufend.Keys)) {
$l = $laufend[$id]
if ($l.angehalten) {
$r = [PbProz]::Fortsetzen($l.p.Id); $l.angehalten = $false
"$id fortgesetzt pid=$($l.p.Id) status=$r $(Get-Date -Format s)" | Add-Content "$D\starter.log"
}
}
"spiel aus: Budget aus GRENZE.txt $(Get-Date -Format s)" | Add-Content "$D\starter.log"
}
$script:spiel = $grund
if ($grund) {
$platz = 2
$reihe = @($laufend.Keys | Sort-Object { [int][bool]$laufend[$_].angehalten }, { $laufend[$_].t })
foreach ($id in $reihe) {
$l = $laufend[$id]
if ($l.p.HasExited) { continue }
if ($l.t -le $platz) {
$platz -= $l.t
if ($l.angehalten) {
$r = [PbProz]::Fortsetzen($l.p.Id); $l.angehalten = $false
"$id fortgesetzt (passt ins Spielbudget) pid=$($l.p.Id) status=$r $(Get-Date -Format s)" | Add-Content "$D\starter.log"
}
} elseif (-not $l.angehalten) {
$r = [PbProz]::Anhalten($l.p.Id); $l.angehalten = $true
"$id angehalten (spiel, $($l.t) Threads) pid=$($l.p.Id) status=$r $(Get-Date -Format s)" | Add-Content "$D\starter.log"
}
}
}
$g = Grenze
$halt = @($laufend.Keys | Where-Object { $laufend[$_].angehalten }) -join ','
$zeile = "spiel=$(if ($grund) { 1 } else { 0 }) threads=$($g.threads) je_lauf=$($g.je_lauf)" +
$(if ($grund) { " grund=$($grund -replace ' ', '_')" } else { '' }) + $(if ($halt) { " angehalten=$halt" } else { '' })
if ($zeile -ne $script:budget_zeile) {
$script:budget_zeile = $zeile
"$zeile seit=$(Get-Date -Format s)" | Set-Content "$D\BUDGET_JETZT.txt" -Encoding ascii
}
}
function Jobs {
if (-not (Test-Path "$D\warteschlange.txt")) { return @() }
@(Get-Content "$D\warteschlange.txt" | Where-Object { $_ -and -not $_.StartsWith('#') })
@@ -121,15 +230,17 @@ function Juengste($id, $l) {
function Wache {
CpuLog
foreach ($id in @($laufend.Keys)) {
$aktiv = @($laufend.Keys | Where-Object { -not $laufend[$_].angehalten })
if ($aktiv.Count -eq 0) { $script:letzter_fortschritt = Get-Date } # nichts laeuft oder alles angehalten
foreach ($id in $aktiv) {
$t = Juengste $id $laufend[$id]
if ($t -gt $script:letzter_fortschritt) { $script:letzter_fortschritt = $t }
}
$still = ((Get-Date) - $script:letzter_fortschritt).TotalMinutes
if ($laufend.Count -gt 0 -and $still -ge 60 -and ((Get-Date) - $script:letzte_warnung).TotalMinutes -ge 60) {
if ($aktiv.Count -gt 0 -and $still -ge 60 -and ((Get-Date) - $script:letzte_warnung).TotalMinutes -ge 60) {
$script:letzte_warnung = Get-Date
$w = "WARNUNG $(Get-Date -Format s): seit $([int]$still) min nichts fertig geworden " +
"(letzter Fortschritt $($script:letzter_fortschritt.ToString('s')), laufend: $(@($laufend.Keys) -join ', '))"
"(letzter Fortschritt $($script:letzter_fortschritt.ToString('s')), laufend: $($aktiv -join ', '))"
$w | Add-Content "$D\starter.log"
$w | Add-Content "$D\cpu.log"
}
@@ -144,8 +255,10 @@ foreach ($j in Jobs) {
$treffer = $prozesse | Where-Object { $_.CommandLine -and $_.CommandLine.Contains($out + ' ') } | Select-Object -First 1
if ($treffer) {
$wd = if ($f.Count -gt 4 -and $f[4]) { $f[4] } else { $D }
$laufend[$f[0]] = @{ p = (Get-Process -Id $treffer.ProcessId); t = (Grenze).je_lauf; fs = (FsPfad $f[3]); out = $out
wd = $wd; gw = (EnvWert $f[3] 'FRUEHSTOPP_GEWINNER') }
$laufend[$f[0]] = @{ p = (Get-Process -Id $treffer.ProcessId); t = (GrenzeDatei).je_lauf; fs = (FsPfad $f[3]); out = $out
wd = $wd; gw = (EnvWert $f[3] 'FRUEHSTOPP_GEWINNER'); angehalten = $false }
# ein frueherer Starter kann ihn bei Spiel angehalten haben: fortsetzen, Spielbudget haelt ggf. neu an
$null = [PbProz]::Fortsetzen($treffer.ProcessId)
"$($f[0]) uebernommen pid=$($treffer.ProcessId) $(Get-Date -Format s)" | Add-Content "$D\starter.log"
}
}
@@ -170,6 +283,7 @@ function Readme-Haken($id) {
$s0 = CpuStand; foreach ($i in $s0.Keys) { $cpu_alt[$i] = $s0[$i].c }; $cpu_zeit = Get-Date
$letzte_pruefung = Get-Date
while ($true) {
try { Spielbudget } catch { "spielbudget fehler $_ $(Get-Date -Format s)" | Add-Content "$D\starter.log" }
if (((Get-Date) - $letzte_wache).TotalMinutes -ge 10) {
$letzte_wache = Get-Date
try { Wache } catch { "wache fehler $_ $(Get-Date -Format s)" | Add-Content "$D\starter.log" }
@@ -208,7 +322,7 @@ while ($true) {
Get-Content "$D\erledigt.txt" | ForEach-Object { $fertig[($_ -split ' ')[0]] = 1 }
$offen = @(Jobs | Where-Object { $i = ($_ -split '\|')[0]; -not $fertig.ContainsKey($i) -and -not $laufend.ContainsKey($i) })
$g = Grenze
$belegt = 0; foreach ($l in $laufend.Values) { $belegt += $l.t }
$belegt = 0; foreach ($l in $laufend.Values) { if (-not $l.angehalten) { $belegt += $l.t } }
$frei = $g.threads - $belegt
if ((Test-Path "$D\STOP") -or $offen.Count -eq 0) {
if ($laufend.Count -eq 0) { break }
@@ -227,7 +341,7 @@ while ($true) {
foreach ($kv in ($env_ -split ';' | Where-Object { $_ })) { Remove-Item "Env:$(($kv -split '=')[0])" -ErrorAction SilentlyContinue }
Remove-Item Env:POKERBENCH_THREADS -ErrorAction SilentlyContinue
$laufend[$id] = @{ p = $p; t = $t; fs = (FsPfad $env_); out = ($args_ -split ' ')[0]; wd = $wd
gw = (EnvWert $env_ 'FRUEHSTOPP_GEWINNER') }
gw = (EnvWert $env_ 'FRUEHSTOPP_GEWINNER'); angehalten = $false }
$letzter_fortschritt = Get-Date
"$id gestartet pid=$($p.Id) threads=$t $(Get-Date -Format s)" | Add-Content "$D\starter.log"
continue