diff --git a/mypy/build.py b/mypy/build.py index c616faccadb37..5e26a511194f5 100644 --- a/mypy/build.py +++ b/mypy/build.py @@ -125,6 +125,7 @@ from mypy.semanal_pass1 import SemanticAnalyzerPreAnalysis from mypy.util import ( DecodeError, + can_start_threads, decode_python_encoding, get_available_threads, get_mypy_comments, @@ -1021,8 +1022,8 @@ def parse_all(self, states: list[State], post_parse: bool = True) -> None: If post_parse is False, skip the last step (used when parsing unchanged files that need to be re-checked due to stale dependencies). """ - if not self.options.native_parser: - # Old parser cannot be parallelized. + if not self.options.native_parser or not can_start_threads(): + # Old parser cannot be parallelized, and some platforms don't support threads. for state in states: state.parse_file() if post_parse: diff --git a/mypy/util.py b/mypy/util.py index a48a7ea824daf..5ad45af77e329 100644 --- a/mypy/util.py +++ b/mypy/util.py @@ -973,6 +973,15 @@ def json_loads(data: bytes) -> Any: _AVAILABLE_THREADS: int | None = None +def can_start_threads() -> bool: + """Can we start new threads? + + WebAssembly builds are typically single-threaded, and starting a thread + fails with RuntimeError there, so we must not even try. + """ + return sys.platform not in ("emscripten", "wasi") + + def get_available_threads() -> int: """Determine number of physical cores that current process can use (best effort).""" global _AVAILABLE_THREADS diff --git a/test-data/unit/fine-grained-blockers.test b/test-data/unit/fine-grained-blockers.test index d201e4f07c941..48faa2cf7752b 100644 --- a/test-data/unit/fine-grained-blockers.test +++ b/test-data/unit/fine-grained-blockers.test @@ -522,7 +522,7 @@ a.py: error: Cannot decode file: 'ascii' codec can't decode byte 0xc3 in positio == main:2: error: Argument 1 to "f" has incompatible type "int"; expected "str" -[case testDecodeErrorBlockerOnInitialRun-posix] +[case testDecodeErrorBlockerOnInitialRun-posix-skip] # Note that there's no test variant for Windows, since the above Windows test case is good enough. import a a.f(1)