iOS: build the _multiprocessing extension (importable, not spawnable)#27
Merged
Conversation
CPython marks _multiprocessing n/a on iOS (with _posixsubprocess/_posixshmem) because process spawning can't work in the sandbox. But the module builds on Darwin (macOS ships it): SemLock via sem_open, socket-based Connection — so importing multiprocessing. connection/synchronize is fine; only Process().start() fails. Packages that import multiprocessing at load without spawning (e.g. scikit-learn's sklearn.callback._transport) currently crash on iOS with ModuleNotFoundError. Flip py_cv_module__multiprocessing to yes in configure (version-agnostic — hits the vendored <3.14 patch and upstream 3.14+ SET_NA), and add ac_cv_func_sem_timedwait/ sem_clockwait=no to CONFIG_SITE (Darwin lacks both) so semaphore.c takes its no-timeout fallback. _posixsubprocess/_posixshmem stay disabled. [skip ci]
FeodorFitsner
approved these changes
Jul 1, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Build the
_multiprocessingC-extension for iOS. CPython marks itn/aon iOS (alongside_posixsubprocessand_posixshmem) because process spawning can't work in the app sandbox. But the extension itself builds fine on Darwin — macOS ships it — andimport multiprocessing[.connection/.synchronize]is perfectly usable. Today, any package that importsmultiprocessingat module load crashes on iOS withModuleNotFoundError: No module named '_multiprocessing'— e.g. scikit-learn'ssklearn.callback._transport, which does an unconditionalfrom multiprocessing.connection import ....This makes
multiprocessingimportable, not runnable.Process().start(),Pool, etc. still fail — that's the inherent iOS sandbox limit, and_posixsubprocess/_posixshmemstay disabled. The goal is only to stop the import-time crash, which is what actually bites in practice.How
Two edits in
darwin/build_ios.py, both after the patch and beforeApple build:configure:py_cv_module__multiprocessing=n/a→=yes. Version-agnostic — it hits both the vendoredios_patches/<3.14configure and upstream 3.14+'sPY_STDLIB_MOD_SET_NA; a no-op if the string isn't present.ac_cv_func_sem_timedwait=noandac_cv_func_sem_clockwait=noto the existingios-config.site(next to the pipe2/dup3 overrides). Darwin has neither; the SDK may still declare them, so this forces_multiprocessing/semaphore.conto its no-timeout fallback instead of referencing symbols that won't link.Validation (3.12.13)
_multiprocessing.xcframeworkwith bothios-arm64andios-arm64_x86_64-simulatorslices (a proper_multiprocessing.frameworkeach) — compiles cleanly through Darwin's missingsem_timedwait._multiprocessing MISSING, 1/5 — only the lazyimport multiprocessingsurvives;.connection,.synchronize,SemLockall fail._multiprocessing PRESENT, 5/5 — including a realSemLockacquire / release /trywaitround-trip (sosem_openworks and the no-sem_timedwaitfallback is fine), plus the.connection/.synchronizeimports packages actually need.Useful for scikit-learn on iOS (flet-dev/mobile-forge#92) without a per-recipe workaround, and fixes the same import crash for every other package that merely imports
multiprocessing.