MCPcopy Create free account
hub / github.com/microsoft/debugpy / attach_connect

Function attach_connect

tests/debug/runners.py:211–271  ·  view source on GitHub ↗
(session, target, method, cwd=None, wait=True, log_dir=None)

Source from the content-addressed store, hash-verified

209
210@_runner
211def attach_connect(session, target, method, cwd=None, wait=True, log_dir=None):
212 log.info(
213 "Attaching {0} to {1} by socket using {2}.", session, target, method.upper()
214 )
215
216 assert method in ("api", "cli")
217
218 config = _attach_common_config(session, target, cwd)
219 config["connect"] = {}
220 config["connect"]["host"] = host = attach_connect.host
221 config["connect"]["port"] = port = attach_connect.port
222
223 if method == "cli":
224 args = [
225 os.path.dirname(debugpy.__file__),
226 "--listen",
227 f"{host}:{port}",
228 ]
229 if wait:
230 args += ["--wait-for-client"]
231 if log_dir is not None:
232 args += ["--log-to", log_dir]
233 if "subProcess" in config:
234 args += ["--configure-subProcess", str(config["subProcess"])]
235 debuggee_setup = None
236 elif method == "api":
237 args = []
238 api_config = {k: v for k, v in config.items() if k in {"subProcess"}}
239 debuggee_setup = """
240import debugpy
241if {log_dir!r}:
242 debugpy.log_to({log_dir!r})
243debugpy.configure({api_config!r})
244debugpy.listen(({host!r}, {port!r}))
245if {wait!r}:
246 debugpy.wait_for_client()
247"""
248 debuggee_setup = debuggee_setup.format(
249 host=host,
250 port=port,
251 wait=wait,
252 log_dir=log_dir,
253 api_config=api_config,
254 )
255 else:
256 raise ValueError
257 args += target.cli(session.spawn_debuggee.env)
258
259 try:
260 del config["subProcess"]
261 except KeyError:
262 pass
263
264 # If adapter is connecting to the client, the server is already started,
265 # so it should be reported in the initial event.
266 session.expect_server_socket()
267
268 session.spawn_debuggee(args, cwd=cwd, setup=debuggee_setup)

Callers

nothing calls this directly

Calls 9

_attach_common_configFunction · 0.85
infoMethod · 0.80
itemsMethod · 0.80
expect_server_socketMethod · 0.80
spawn_debuggeeMethod · 0.80
connect_to_adapterMethod · 0.80
request_attachMethod · 0.80
cliMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…