Skip to content

Commit b5146c4

Browse files
committed
fix(ios): re-enable _posixshmem so multiprocessing (resource_tracker) imports
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.
1 parent dc76612 commit b5146c4

1 file changed

Lines changed: 21 additions & 8 deletions

File tree

darwin/build_ios.py

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -120,18 +120,31 @@ def build(
120120
for shim in bindir.glob("*") if bindir.is_dir() else []:
121121
shim.chmod(0o755)
122122

123-
# Re-enable _multiprocessing on iOS. CPython marks it (with _posixsubprocess and
124-
# _posixshmem) n/a for iOS because process *spawning* is impossible in the sandbox
125-
# (no usable fork/exec). But _multiprocessing itself — SemLock via sem_open, and
126-
# socket-based Connection/Listener — builds fine on Darwin (macOS ships it); only
127-
# the spawning is unusable. Flipping this makes `import multiprocessing[.connection/.synchronize]`
128-
# succeed, without pretending subprocess works. Hits both the vendored-patch configure
129-
# (<3.14) and upstream's iOS PY_STDLIB_MOD_SET_NA (3.14+); a no-op if the string isn't present.
123+
# Re-enable _multiprocessing AND _posixshmem on iOS. CPython marks them (with
124+
# _posixsubprocess) n/a for iOS because process *spawning* is impossible in the
125+
# sandbox (no usable fork/exec). But _multiprocessing itself — SemLock via
126+
# sem_open, and socket-based Connection/Listener — builds fine on Darwin (macOS
127+
# ships it); only the spawning is unusable. Flipping this makes `import
128+
# multiprocessing[.connection/.synchronize]` succeed, without pretending
129+
# subprocess works.
130+
#
131+
# _posixshmem must be flipped too: `multiprocessing.resource_tracker` (imported
132+
# transitively by `import multiprocessing`, e.g. scikit-learn -> joblib) does an
133+
# UNCONDITIONAL `import _posixshmem` on posix, so with _multiprocessing enabled
134+
# but _posixshmem absent, that import raises ModuleNotFoundError and takes the
135+
# whole consumer down. shm_open/shm_unlink build fine on Darwin/iOS (the sandbox
136+
# restricts USE, not the build; nothing here uses shared memory), and upstream
137+
# 3.13's official iOS support ships _posixshmem too. _posixsubprocess stays n/a
138+
# (it genuinely needs fork/exec). Hits both the vendored-patch configure (<3.14)
139+
# and upstream's iOS PY_STDLIB_MOD_SET_NA (3.14+); a no-op if the string isn't
140+
# present.
130141
configure = src / "configure"
131142
configure.write_text(
132-
configure.read_text().replace(
143+
configure.read_text()
144+
.replace(
133145
"py_cv_module__multiprocessing=n/a", "py_cv_module__multiprocessing=yes"
134146
)
147+
.replace("py_cv_module__posixshmem=n/a", "py_cv_module__posixshmem=yes")
135148
)
136149

137150
# iOS's SDK declares pipe2/dup3 in headers but doesn't provide them, and on recent

0 commit comments

Comments
 (0)