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

Function main

src/debugpy/adapter/__main__.py:16–138  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

14
15
16def main():
17 args = _parse_argv(sys.argv)
18
19 # If we're talking DAP over stdio, stderr is not guaranteed to be read from,
20 # so disable it to avoid the pipe filling and locking up. This must be done
21 # as early as possible, before the logging module starts writing to it.
22 if args.port is None:
23 sys.stderr = stderr = open(os.devnull, "w")
24 atexit.register(stderr.close)
25
26 from debugpy import adapter
27 from debugpy.common import json, log, sockets
28 from debugpy.adapter import clients, servers, sessions
29
30 if args.for_server is not None:
31 if os.name == "posix":
32 # On POSIX, we need to leave the process group and its session, and then
33 # daemonize properly by double-forking (first fork already happened when
34 # this process was spawned).
35 # NOTE: if process is already the session leader, then
36 # setsid would fail with `operation not permitted`
37 if os.getsid(os.getpid()) != os.getpid():
38 os.setsid()
39 if os.fork() != 0:
40 sys.exit(0)
41
42 for stdio in sys.stdin, sys.stdout, sys.stderr:
43 if stdio is not None:
44 stdio.close()
45
46 if args.log_stderr:
47 log.stderr.levels |= set(log.LEVELS)
48 if args.log_dir is not None:
49 log.log_dir = args.log_dir
50
51 log.to_file(prefix="debugpy.adapter")
52 log.describe_environment("debugpy.adapter startup environment:")
53
54 servers.access_token = args.server_access_token
55 if args.for_server is None:
56 adapter.access_token = codecs.encode(os.urandom(32), "hex").decode("ascii")
57
58 endpoints = {}
59 try:
60 client_host, client_port = clients.serve(args.host, args.port)
61 except Exception as exc:
62 if args.for_server is None:
63 raise
64 endpoints = {"error": "Can't listen for client connections: " + str(exc)}
65 else:
66 endpoints["client"] = {"host": client_host, "port": client_port}
67
68 localhost = sockets.get_default_localhost()
69 if args.for_server is not None:
70 try:
71 server_host, server_port = servers.serve(localhost)
72 except Exception as exc:
73 endpoints = {"error": "Can't listen for server connections: " + str(exc)}

Callers 1

__main__.pyFile · 0.70

Calls 10

_parse_argvFunction · 0.85
registerMethod · 0.80
infoMethod · 0.80
dumpsMethod · 0.80
errorMethod · 0.80
closeMethod · 0.45
decodeMethod · 0.45
countMethod · 0.45
connectMethod · 0.45
writeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…