import sys,json,time,os,signal,threading from pathlib import Path sys.path.insert(0,'/app') from catalog import Catalog from profiles import Profiles from runtime import Runtime from inference import LlamaWorker root=Path('/var/lib/deck');work=root/'benchmark-practice-20261011';work.mkdir(exist_ok=True) c=Catalog(root/'models');ps=Profiles(root/'profiles.json',c);w=LlamaWorker(work/'worker',c,Runtime(root/'runtime')) p=next(x for x in ps.status()['profiles'] if x['name']=='Qwen3.8 27B - Medium') release=threading.Event();cancel=threading.Event() def release_tts(): while not release.is_set(): for proc in Path('/proc').glob('[0-9]*/cmdline'): try: exe=proc.read_bytes().split(b'\0',1)[0].decode() if exe.startswith('/var/lib/deck/tts-runtime/') and exe.endswith('/python/bin/python'):os.kill(int(proc.parent.name),signal.SIGTERM) except (OSError,UnicodeError):pass release.wait(.5) def production_present(): for proc in Path('/proc').glob('[0-9]*/cmdline'): try: args=proc.read_bytes().decode().split('\0') if args and args[0].endswith('/llama-server') and str(root/'llama-worker/worker.key') in args:return True except (OSError,UnicodeError):pass return False try: if production_present():raise RuntimeError('Production LLM loaded: leave it untouched and abort') th=threading.Thread(target=release_tts,daemon=True);th.start();time.sleep(.6) try:w.ensure(p,cancel=cancel.is_set) finally:release.set();th.join(2) conn,key=w.connect();dest=work/'model-private.json';dest.write_text(json.dumps({'url':'http://127.0.0.1:'+str(conn.port),'key':key,'model':p['name']}));dest.chmod(0o600);conn.close() (work/'parameters-public.json').write_text(json.dumps(p['parameters'],indent=2));print('READY: original Medium profile loaded',flush=True) while not (work/'STOP').exists(): if production_present():raise RuntimeError('Production LLM resumed: stop isolated test worker') time.sleep(1) finally:w.stop()