MCPcopy Create free account
hub / github.com/commandoperator/cmdop-sdk / _ensure_started

Method _ensure_started

python/src/cmdop/_transport.py:103–129  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

101 # -- lifecycle ---------------------------------------------------------
102
103 async def _ensure_started(self) -> asyncio.subprocess.Process:
104 if self._proc is not None:
105 return self._proc
106 async with self._start_lock:
107 if self._proc is not None:
108 return self._proc
109 env = {
110 **os.environ,
111 "CMDOP_TOKEN": self._cfg.token,
112 "CMDOP_BASE_URL": self._cfg.base_url,
113 # Django platform plane (skills) — separate credential + base URL.
114 "CMDOP_API_BASE_URL": self._cfg.api_base_url,
115 }
116 if self._cfg.api_key:
117 env["CMDOP_API_KEY"] = self._cfg.api_key
118 proc = await asyncio.create_subprocess_exec(
119 self._bin,
120 "--stdio",
121 stdin=asyncio.subprocess.PIPE,
122 stdout=asyncio.subprocess.PIPE,
123 stderr=asyncio.subprocess.PIPE,
124 env=env,
125 )
126 self._proc = proc
127 self._reader_task = asyncio.create_task(self._read_loop())
128 self._stderr_task = asyncio.create_task(self._drain_stderr())
129 return proc
130
131 async def _drain_stderr(self) -> None:
132 """Drain the core's stderr so its diagnostics never block / corrupt the

Callers 3

write_answerMethod · 0.95
call_unaryMethod · 0.95
_start_streamMethod · 0.95

Calls 2

_read_loopMethod · 0.95
_drain_stderrMethod · 0.95

Tested by

no test coverage detected