(argv: list[str])
| 82 | |
| 83 | |
| 84 | def 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 | |
| 140 | def should_shutdown(buf: ReadBuffer, expected_tag: Tag) -> bool: |
no test coverage detected
searching dependent graphs…