intel_child_stub.py
python
sha256:f0ce9f515a530043854b2549a902d0df78837898e9e9439fe32abeee180bef85
feat(worker): run intel jobs in a bounded child process; th…
Sonnet 5.5
patch
4 days ago
| 1 | """Stand-in for ``musehub.intel_child`` that speaks its protocol with scriptable misbehaviour (used by test_intel_supervisor.py; no database).""" |
| 2 | import json |
| 3 | import os |
| 4 | import sys |
| 5 | import time |
| 6 | |
| 7 | pid_file = os.environ.get("STUB_PID_FILE") |
| 8 | if pid_file: |
| 9 | open(pid_file, "w").write(str(os.getpid())) |
| 10 | held = [] |
| 11 | for line in sys.stdin: |
| 12 | req = json.loads(line) |
| 13 | kind = req["job_type"] |
| 14 | if kind == "ok": |
| 15 | reply = {"ok": True, "terminal": "done", "result": {"pid": os.getpid(), "echo": req["payload"]}} |
| 16 | elif kind == "fail": |
| 17 | reply = {"ok": False, "error": "Traceback: ValueError('boom')"} |
| 18 | elif kind == "hang": |
| 19 | time.sleep(600) |
| 20 | continue |
| 21 | elif kind == "alloc": |
| 22 | held.append(bytearray(int(req["payload"]["mib"]) * 1024 * 1024)) |
| 23 | for i in range(0, len(held[-1]), 4096): |
| 24 | held[-1][i] = 1 # touch every page so it is resident |
| 25 | time.sleep(600) |
| 26 | continue |
| 27 | elif kind == "burn": |
| 28 | end = time.process_time() + 600 |
| 29 | while time.process_time() < end: |
| 30 | pass |
| 31 | continue |
| 32 | elif kind == "die": |
| 33 | os._exit(9) |
| 34 | else: |
| 35 | reply = {"ok": True, "terminal": "done", "result": {}} |
| 36 | sys.stdout.write(json.dumps(reply) + "\n") |
| 37 | sys.stdout.flush() |
File History
1 commit
sha256:f0ce9f515a530043854b2549a902d0df78837898e9e9439fe32abeee180bef85
feat(worker): run intel jobs in a bounded child process; th…
Sonnet 5.5
patch
4 days ago