MCPcopy Index your code
hub / github.com/python/mypy / main

Function main

mypy/build_worker/worker.py:84–137  ·  view source on GitHub ↗
(argv: list[str])

Source from the content-addressed store, hash-verified

82
83
84def main(argv: list[str]) -> None:
85 # Set recursion limit and GC thresholds consistent with mypy/main.py
86 sys.setrecursionlimit(RECURSION_LIMIT)
87 if platform.python_implementation() == "CPython":
88 gc.set_threshold(200 * 1000, 30, 30)
89
90 args = parser.parse_args(argv)
91
92 # This mimics how daemon receives the options. Note we need to postpone
93 # processing error codes after plugins are loaded, because plugins can add
94 # custom error codes.
95 with open(args.options_data, "rb") as f:
96 buf = ReadBuffer(f.read())
97 options_dict = read_json(buf)
98 disable_error_code = options_dict.pop("disable_error_code", [])
99 enable_error_code = options_dict.pop("enable_error_code", [])
100 options = Options().apply_changes(options_dict)
101
102 status_file = args.status_file
103 server = IPCServer(CONNECTION_NAME, WORKER_CONNECTION_TIMEOUT)
104
105 try:
106 with open(status_file, "w") as f:
107 json.dump({"pid": os.getpid(), "connection_name": server.connection_name}, f)
108 f.write("\n")
109 except Exception as exc:
110 print(f"Error writing status file {status_file}:", exc)
111 raise
112
113 fscache = FileSystemCache()
114 fscache.set_package_root(options.package_root)
115 cached_read = fscache.read
116 error_formatter = None if options.output is None else OUTPUT_CHOICES.get(options.output)
117 errors = Errors(
118 options,
119 read_source=lambda path: read_py_file(path, cached_read),
120 error_formatter=error_formatter,
121 )
122
123 ctx = ServerContext(options, disable_error_code, enable_error_code, errors, fscache)
124 try:
125 with server:
126 serve(server, ctx)
127 except (OSError, IPCException) as exc:
128 if options.verbosity >= 1:
129 print("Error communicating with coordinator:", exc)
130 except Exception as exc:
131 report_internal_error(exc, errors.file, 0, errors, options)
132 finally:
133 server.cleanup()
134
135 if options.fast_exit:
136 # Exit fast if allowed, since coordinator is waiting on us.
137 util.hard_exit(0)
138
139
140def should_shutdown(buf: ReadBuffer, expected_tag: Tag) -> bool:

Callers 1

console_entryFunction · 0.70

Calls 15

set_package_rootMethod · 0.95
cleanupMethod · 0.95
read_jsonFunction · 0.90
OptionsClass · 0.90
IPCServerClass · 0.90
FileSystemCacheClass · 0.90
ErrorsClass · 0.90
read_py_fileFunction · 0.90
report_internal_errorFunction · 0.90
printFunction · 0.85
ServerContextClass · 0.85
serveFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…