From b5146c4591a66fc312adf2130cfeadc57923fe32 Mon Sep 17 00:00:00 2001 From: ndonkoHenri Date: Mon, 13 Jul 2026 12:24:03 +0200 Subject: [PATCH] fix(ios): re-enable _posixshmem so multiprocessing (resource_tracker) imports MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit build_ios.py already flips py_cv_module__multiprocessing=n/a -> yes for iOS (SemLock/sockets build fine on Darwin; only spawning is unusable), but left _posixshmem n/a. multiprocessing.resource_tracker does an UNCONDITIONAL `import _posixshmem` on posix, so with _multiprocessing enabled but _posixshmem absent, ANY transitive multiprocessing import fails on iOS with `ModuleNotFoundError: No module named '_posixshmem'` — e.g. scikit-learn (sklearn.utils.validation -> joblib -> multiprocessing) crashes at import. shm_open/shm_unlink build fine on Darwin/iOS (the sandbox restricts USE, not the build; nothing here uses shared memory), and upstream 3.13's official iOS support ships _posixshmem. So flip py_cv_module__posixshmem=n/a -> yes the same way. _posixsubprocess stays n/a (genuinely needs fork/exec). Fixes the scikit-learn iOS mobile-test import crash (flet 0.86 recipe-tester). Needs an iOS python-build rebuild + a new support run-id for CI to pick it up. --- darwin/build_ios.py | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/darwin/build_ios.py b/darwin/build_ios.py index 198d78c..8087272 100644 --- a/darwin/build_ios.py +++ b/darwin/build_ios.py @@ -120,18 +120,31 @@ def build( for shim in bindir.glob("*") if bindir.is_dir() else []: shim.chmod(0o755) - # Re-enable _multiprocessing on iOS. CPython marks it (with _posixsubprocess and - # _posixshmem) n/a for iOS because process *spawning* is impossible in the sandbox - # (no usable fork/exec). But _multiprocessing itself — SemLock via sem_open, and - # socket-based Connection/Listener — builds fine on Darwin (macOS ships it); only - # the spawning is unusable. Flipping this makes `import multiprocessing[.connection/.synchronize]` - # succeed, without pretending subprocess works. Hits both the vendored-patch configure - # (<3.14) and upstream's iOS PY_STDLIB_MOD_SET_NA (3.14+); a no-op if the string isn't present. + # Re-enable _multiprocessing AND _posixshmem on iOS. CPython marks them (with + # _posixsubprocess) n/a for iOS because process *spawning* is impossible in the + # sandbox (no usable fork/exec). But _multiprocessing itself — SemLock via + # sem_open, and socket-based Connection/Listener — builds fine on Darwin (macOS + # ships it); only the spawning is unusable. Flipping this makes `import + # multiprocessing[.connection/.synchronize]` succeed, without pretending + # subprocess works. + # + # _posixshmem must be flipped too: `multiprocessing.resource_tracker` (imported + # transitively by `import multiprocessing`, e.g. scikit-learn -> joblib) does an + # UNCONDITIONAL `import _posixshmem` on posix, so with _multiprocessing enabled + # but _posixshmem absent, that import raises ModuleNotFoundError and takes the + # whole consumer down. shm_open/shm_unlink build fine on Darwin/iOS (the sandbox + # restricts USE, not the build; nothing here uses shared memory), and upstream + # 3.13's official iOS support ships _posixshmem too. _posixsubprocess stays n/a + # (it genuinely needs fork/exec). Hits both the vendored-patch configure (<3.14) + # and upstream's iOS PY_STDLIB_MOD_SET_NA (3.14+); a no-op if the string isn't + # present. configure = src / "configure" configure.write_text( - configure.read_text().replace( + configure.read_text() + .replace( "py_cv_module__multiprocessing=n/a", "py_cv_module__multiprocessing=yes" ) + .replace("py_cv_module__posixshmem=n/a", "py_cv_module__posixshmem=yes") ) # iOS's SDK declares pipe2/dup3 in headers but doesn't provide them, and on recent