FILE: projects/switch_ll4d_guarded.py
SIZE: 1794 bytes
SHA256: 2fa0f266b29a3c91cda7197915cdd96a4a9cbfe45ac3fda08867cfaf94115770
Lines: 18
Use path as FILE | Patch Context | Read first 100 | Read prev 100 | Read next 100 | Git diff this file | Code Buffers | Active Patch Context
| Line | Text | Actions |
|---|---|---|
| 1 | from pathlib import Path | Use FILE Use as OLD Use as NEW Open Patch Composer +/-3 CONTEXT +/-10 CONTEXT +/-25 CONTEXT Append to Buffer A |
| 2 | import ctypes,hashlib,os,subprocess,sys,time | Use FILE Use as OLD Use as NEW Open Patch Composer +/-3 CONTEXT +/-10 CONTEXT +/-25 CONTEXT Append to Buffer A |
| 3 | ROOT=Path(__file__).resolve().parents[1]; PROJECTS=ROOT/'projects'; WRAPPER=PROJECTS/'low_latency_relay_v4diag.py'; OLD_PID=9848; EXPECTED_SHA='f7771f74edab5f7194c8076346af4e5c339ae5f2a9d29213adea71f14e6496f1'; LOCK=ROOT/'bridge-data'/'sheet-relay'/'ll4d-switch-20260830.lock' | Use FILE Use as OLD Use as NEW Open Patch Composer +/-3 CONTEXT +/-10 CONTEXT +/-25 CONTEXT Append to Buffer A |
| 4 | LOCK.parent.mkdir(parents=True,exist_ok=True) | Use FILE Use as OLD Use as NEW Open Patch Composer +/-3 CONTEXT +/-10 CONTEXT +/-25 CONTEXT Append to Buffer A |
| 5 | try: fd=os.open(str(LOCK),os.O_CREAT|os.O_EXCL|os.O_WRONLY) | Use FILE Use as OLD Use as NEW Open Patch Composer +/-3 CONTEXT +/-10 CONTEXT +/-25 CONTEXT Append to Buffer A |
| 6 | except FileExistsError: print('SWITCH_ALREADY_CLAIMED'); raise SystemExit(0) | Use FILE Use as OLD Use as NEW Open Patch Composer +/-3 CONTEXT +/-10 CONTEXT +/-25 CONTEXT Append to Buffer A |
| 7 | with os.fdopen(fd,'w') as f:f.write(str(time.time())) | Use FILE Use as OLD Use as NEW Open Patch Composer +/-3 CONTEXT +/-10 CONTEXT +/-25 CONTEXT Append to Buffer A |
| 8 | if hashlib.sha256(WRAPPER.read_bytes()).hexdigest()!=EXPECTED_SHA: raise SystemExit('SHA_MISMATCH') | Use FILE Use as OLD Use as NEW Open Patch Composer +/-3 CONTEXT +/-10 CONTEXT +/-25 CONTEXT Append to Buffer A |
| 9 | compile(WRAPPER.read_text(encoding='utf-8'),str(WRAPPER),'exec') | Use FILE Use as OLD Use as NEW Open Patch Composer +/-3 CONTEXT +/-10 CONTEXT +/-25 CONTEXT Append to Buffer A |
| 10 | p=subprocess.run(['powershell','-NoProfile','-Command',f"$p=Get-CimInstance Win32_Process -Filter 'ProcessId={OLD_PID}' -ErrorAction SilentlyContinue; if($p){{$p.CommandLine}}"],capture_output=True,text=True); old=p.stdout.strip(); print('OLD_CMD='+old) | Use FILE Use as OLD Use as NEW Open Patch Composer +/-3 CONTEXT +/-10 CONTEXT +/-25 CONTEXT Append to Buffer A |
| 11 | if 'low_latency_relay_v3test.py' not in old: raise SystemExit('OLD_PID_GUARD_FAILED') | Use FILE Use as OLD Use as NEW Open Patch Composer +/-3 CONTEXT +/-10 CONTEXT +/-25 CONTEXT Append to Buffer A |
| 12 | k=subprocess.run(['taskkill','/PID',str(OLD_PID),'/F'],capture_output=True,text=True); print('TASKKILL_RC='+str(k.returncode)); | Use FILE Use as OLD Use as NEW Open Patch Composer +/-3 CONTEXT +/-10 CONTEXT +/-25 CONTEXT Append to Buffer A |
| 13 | if k.returncode!=0: raise SystemExit('KILL_FAILED') | Use FILE Use as OLD Use as NEW Open Patch Composer +/-3 CONTEXT +/-10 CONTEXT +/-25 CONTEXT Append to Buffer A |
| 14 | flags=getattr(subprocess,'CREATE_NO_WINDOW',0); new=subprocess.Popen([sys.executable,str(WRAPPER)],cwd=str(ROOT),stdin=subprocess.DEVNULL,stdout=subprocess.DEVNULL,stderr=subprocess.DEVNULL,creationflags=flags); time.sleep(2) | Use FILE Use as OLD Use as NEW Open Patch Composer +/-3 CONTEXT +/-10 CONTEXT +/-25 CONTEXT Append to Buffer A |
| 15 | if new.poll() is not None: raise SystemExit('START_FAILED') | Use FILE Use as OLD Use as NEW Open Patch Composer +/-3 CONTEXT +/-10 CONTEXT +/-25 CONTEXT Append to Buffer A |
| 16 | try: ok=bool(ctypes.windll.kernel32.SetPriorityClass(int(new._handle),0x00008000)) | Use FILE Use as OLD Use as NEW Open Patch Composer +/-3 CONTEXT +/-10 CONTEXT +/-25 CONTEXT Append to Buffer A |
| 17 | except Exception: ok=False | Use FILE Use as OLD Use as NEW Open Patch Composer +/-3 CONTEXT +/-10 CONTEXT +/-25 CONTEXT Append to Buffer A |
| 18 | print('SWITCH_OK'); print('NEW_PID='+str(new.pid)); print('REVISION=20260830-107-LL4D'); print('PRIORITY_ABOVE_NORMAL='+str(ok)) | Use FILE Use as OLD Use as NEW Open Patch Composer +/-3 CONTEXT +/-10 CONTEXT +/-25 CONTEXT Append to Buffer A |