Commit 5e21d22
committed
Pre-spawn process worker in cli.py to avoid the fds_to_keep race
The first two commits made the macOS Tahoe segfault non-fatal by
disabling the fork fallback, but every spawn after Textual booted
still failed with `bad value(s) in fds_to_keep` — leaving the user
with a "Process worker unavailable; falling back" popup and the
slower in-process executor on every query.
Root cause: `multiprocessing.spawn` snapshots the parent's open file
descriptors at spawn time. Once Textual's `App.__init__` has
registered its signal-handler pipes and event-loop FDs, several of
those are not inheritable, and spawn aborts before the child even
runs. The previous lazy creation in the idle scheduler always hit
this race.
Fix: spawn the worker in `cli.py` *before* `SSMSTUI(...)` is
constructed. That's the latest moment at which the parent's FD set
is still clean. The new `_prewarm_process_worker(runtime)` helper
returns a live `ProcessWorkerClient`, or `None` if the worker is
disabled / mocked / spawn raised — in which case we fall through to
the lazy path inside the UI (with the in-process fallback on
darwin).
The pre-spawned client is passed into `SSMSTUI` via a new
`process_worker_client` kwarg and stashed as
`self._process_worker_client`. `ProcessWorkerLifecycleMixin` already
returns the cached client first, so no other changes are needed.
Verified on macOS Tahoe 26.4.1 / Python 3.14 / PostgreSQL over TLS:
the popup no longer appears and queries run in the worker process.1 parent b32fdee commit 5e21d22
2 files changed
Lines changed: 43 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
177 | 177 | | |
178 | 178 | | |
179 | 179 | | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
180 | 206 | | |
181 | 207 | | |
182 | 208 | | |
| |||
843 | 869 | | |
844 | 870 | | |
845 | 871 | | |
| 872 | + | |
| 873 | + | |
| 874 | + | |
846 | 875 | | |
847 | 876 | | |
848 | 877 | | |
849 | 878 | | |
| 879 | + | |
850 | 880 | | |
851 | 881 | | |
852 | 882 | | |
| |||
907 | 937 | | |
908 | 938 | | |
909 | 939 | | |
910 | | - | |
| 940 | + | |
| 941 | + | |
| 942 | + | |
| 943 | + | |
| 944 | + | |
| 945 | + | |
911 | 946 | | |
912 | 947 | | |
913 | 948 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
100 | 100 | | |
101 | 101 | | |
102 | 102 | | |
| 103 | + | |
103 | 104 | | |
104 | 105 | | |
105 | 106 | | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
106 | 113 | | |
107 | 114 | | |
108 | 115 | | |
| |||
0 commit comments