MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / run

Method run

tests/coverage_live_v2_support.py:74–167  ·  view source on GitHub ↗
(self, label, argv, env=None, timeout=180)

Source from the content-addressed store, hash-verified

72 return False
73
74 def run(self, label, argv, env=None, timeout=180):
75 if STOP.is_set():
76 raise KeyboardInterrupt("driver stop requested")
77 directory = self.root / ("%03d-%s" % (len(self.records), label))
78 directory.mkdir()
79 record = {"label": label, "argv": [str(x) for x in argv], "timeout": timeout,
80 "stdout": str(directory / "stdout.log"),
81 "stderr": str(directory / "stderr.log"), "cleanup": []}
82 self.records.append(record)
83 state = {"bytes": 0, "overflow": False, "errors": []}
84 lock = threading.Lock()
85 stop = threading.Event()
86 started = time.monotonic()
87 try:
88 process = subprocess.Popen(record["argv"], env=env, stdin=subprocess.DEVNULL,
89 stdout=subprocess.PIPE, stderr=subprocess.PIPE,
90 start_new_session=True, bufsize=0)
91 except OSError as exc:
92 record["launch_error"] = str(exc)
93 write_json(directory / "process.json", record)
94 raise Infrastructure("command launch failed: " + label) from exc
95 record["pid"] = process.pid
96
97 def drain(source, destination):
98 try:
99 with Path(destination).open("xb") as output:
100 while True:
101 block = source.read(65536)
102 if not block:
103 break
104 with lock:
105 remaining = max(0, min(64 * 1024 * 1024 - state["bytes"],
106 512 * 1024 * 1024 - self.total_output_bytes))
107 state["bytes"] += len(block)
108 self.total_output_bytes += len(block)
109 if len(block) > remaining:
110 state["overflow"] = True
111 stop.set()
112 output.write(block[:remaining])
113 except Exception as exc:
114 with lock:
115 state["errors"].append(str(exc))
116 stop.set()
117 finally:
118 source.close()
119
120 threads = [threading.Thread(target=drain, args=(source, record[name]), daemon=True)
121 for source, name in ((process.stdout, "stdout"), (process.stderr, "stderr"))]
122 timed_out, interrupted = False, None
123 try:
124 write_json(directory / "started.json", record)
125 for thread in threads:
126 thread.start()
127 while process.poll() is None and not stop.is_set() and not STOP.is_set():
128 if time.monotonic() - started >= timeout:
129 timed_out = True
130 break
131 stop.wait(0.02)

Callers

nothing calls this directly

Calls 11

group_aliveMethod · 0.95
strFunction · 0.85
zipFunction · 0.85
startMethod · 0.80
waitMethod · 0.80
updateMethod · 0.80
write_jsonFunction · 0.70
InfrastructureClass · 0.70
allFunction · 0.50
pollMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected