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 <noreply@anthropic.com>
This commit is contained in:
2026-11-29 09:31:22 +01:00
co-authored by Claude Opus 5.5
parent aebad5481f
commit 48352acdf4
2 changed files with 65 additions and 1 deletions
+64
View File
@@ -0,0 +1,64 @@
"""Halter (29.11.): meine lauf.sh-Tische anhalten oder fortsetzen (NtSuspendProcess/NtResumeProcess, ganzer Baum), nichts beenden.
python halter.py an <muster> ... 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()
+1 -1
View File
@@ -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)