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

Function attach

src/debugpy/server/attach_pid_injected.py:14–92  ·  view source on GitHub ↗
(setup)

Source from the content-addressed store, hash-verified

12
13
14def attach(setup):
15 log = None
16 try:
17 import sys
18
19 if "threading" not in sys.modules:
20 try:
21
22 def on_warn(msg):
23 print(msg, file=sys.stderr)
24
25 def on_exception(msg):
26 print(msg, file=sys.stderr)
27
28 def on_critical(msg):
29 print(msg, file=sys.stderr)
30
31 pydevd_attach_to_process_path = os.path.join(
32 _debugpy_dir,
33 "debugpy",
34 "_vendored",
35 "pydevd",
36 "pydevd_attach_to_process",
37 )
38 assert os.path.exists(pydevd_attach_to_process_path)
39 sys.path.insert(0, pydevd_attach_to_process_path)
40
41 # NOTE: that it's not a part of the pydevd PYTHONPATH
42 import attach_script
43
44 attach_script.fix_main_thread_id(
45 on_warn=on_warn, on_exception=on_exception, on_critical=on_critical
46 )
47
48 # NOTE: At this point it should be safe to remove this.
49 sys.path.remove(pydevd_attach_to_process_path)
50 except:
51 import traceback
52
53 traceback.print_exc()
54 raise
55
56 sys.path.insert(0, _debugpy_dir)
57 try:
58 import debugpy
59 import debugpy.server
60 from debugpy.common import json, log
61 import pydevd
62 finally:
63 assert sys.path[0] == _debugpy_dir
64 del sys.path[0]
65
66 py_db = pydevd.get_global_debugger()
67 if py_db is not None:
68 py_db.dispose_and_kill_all_pydevd_threads(wait=False)
69
70 if setup["log_to"] is not None:
71 debugpy.log_to(setup["log_to"])

Callers

nothing calls this directly

Calls 7

reprFunction · 0.85
infoMethod · 0.80
listenMethod · 0.80
joinMethod · 0.45
removeMethod · 0.45
connectMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…