From 48352acdf45cec5c5dad7a5104b54fef25e2cb33 Mon Sep 17 00:00:00 2001 From: Marc Mintel Date: Sun, 29 Nov 2026 09:31:22 +0100 Subject: [PATCH] halter.py: Tische anhalten/fortsetzen (Baum, NtSuspend), waechter weckt nicht bei daten/HALTER.json; shf-3v3 und foldrundung angehalten Co-Authored-By: Claude Opus 5.5 --- messung/motor/pruef6/sharingan/halter.py | 64 ++++++++++++++++++++++ messung/motor/pruef6/sharingan/waechter.py | 2 +- 2 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 messung/motor/pruef6/sharingan/halter.py diff --git a/messung/motor/pruef6/sharingan/halter.py b/messung/motor/pruef6/sharingan/halter.py new file mode 100644 index 00000000..a1fa291d --- /dev/null +++ b/messung/motor/pruef6/sharingan/halter.py @@ -0,0 +1,64 @@ +"""Halter (29.11.): meine lauf.sh-Tische anhalten oder fortsetzen (NtSuspendProcess/NtResumeProcess, ganzer Baum), nichts beenden. + + python halter.py an ... haelt jeden Baum an, dessen Wurzel-Kommandozeile ein Muster enthaelt; schreibt daten/HALTER.json + python halter.py aus setzt die in daten/HALTER.json genannten Prozesse fort und loescht die Datei +Solange daten/HALTER.json besteht, weckt waechter.py nichts auf. +""" +import ctypes +import json +import os +import subprocess +import sys + +HIER = os.path.dirname(os.path.abspath(__file__)) +DATEI = os.path.join(HIER, "daten", "HALTER.json") +nt = ctypes.windll.ntdll +k32 = ctypes.windll.kernel32 + + +def prozesse(): + o = subprocess.run(["powershell", "-NoProfile", "-c", + "Get-CimInstance Win32_Process | Select ProcessId,ParentProcessId,Name,CommandLine | ConvertTo-Json -Compress"], + capture_output=True, text=True, encoding="utf-8", errors="replace", creationflags=0x08000000).stdout or "[]" + return json.loads(o) + + +def setze(ids, halt): + for i in ids: + h = k32.OpenProcess(0x0800, False, i) # PROCESS_SUSPEND_RESUME + if h: + (nt.NtSuspendProcess if halt else nt.NtResumeProcess)(h) + k32.CloseHandle(h) + + +def main(): + if sys.argv[1] == "an": + ps = prozesse() + kinder = {} + for p in ps: + kinder.setdefault(p["ParentProcessId"], []).append(p) + wurzeln = [p for p in ps if p["Name"] == "python.exe" and "tisch6.py" in (p["CommandLine"] or "") + and any(m in p["CommandLine"] for m in sys.argv[2:])] + alle = [] + for w in wurzeln: + stapel = [w] + while stapel: + p = stapel.pop() + alle.append({"pid": p["ProcessId"], "name": p["Name"], "cmd": (p["CommandLine"] or "")[:160]}) + stapel += kinder.get(p["ProcessId"], []) + alt = json.load(open(DATEI, encoding="utf-8")) if os.path.exists(DATEI) else [] + setze([p["pid"] for p in alle], True) + tmp = DATEI + ".neu" + json.dump(alt + alle, open(tmp, "w", encoding="utf-8"), ensure_ascii=False, indent=1) + os.replace(tmp, DATEI) + for p in alle: + print("angehalten", p["pid"], p["name"], p["cmd"][:100]) + else: + alle = json.load(open(DATEI, encoding="utf-8")) + setze([p["pid"] for p in alle], False) + os.remove(DATEI) + print("fortgesetzt", len(alle)) + + +if __name__ == "__main__": + main() diff --git a/messung/motor/pruef6/sharingan/waechter.py b/messung/motor/pruef6/sharingan/waechter.py index 5b15d738..889b893e 100644 --- a/messung/motor/pruef6/sharingan/waechter.py +++ b/messung/motor/pruef6/sharingan/waechter.py @@ -91,7 +91,7 @@ def main(): setze(m - angehalten, True) angehalten |= m print(time.strftime("%H:%M"), "frei %d GB, Platte %.1f GB%s -> meine angehalten" % (g, pl, ", Laeufer spielt" if s else ""), flush=True) - elif angehalten and g >= OBEN and not s and pl >= PLATTE_OBEN: + elif angehalten and g >= OBEN and not s and pl >= PLATTE_OBEN and not os.path.exists(os.path.join(HIER, "daten", "HALTER.json")): # Halter: nie wecken setze(angehalten, False) angehalten = set() print(time.strftime("%H:%M"), "frei %d GB -> meine fortgesetzt" % g, flush=True)