# subprocess.\_USE\_VFORK escape hatch broken, fix or remove?

**URL:** <https://discuss.python.org/t/subprocess-use-vfork-escape-hatch-broken-fix-or-remove/56915>\
**Category:** Core Development\
**Tags:** stdlib\
**Created:** [June 28, 2024, 10:07pm UTC](https://discuss.python.org/t/subprocess-use-vfork-escape-hatch-broken-fix-or-remove/56915 "2024-06-28T22:07:41Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![cmaloney](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/cmaloney/32/15851_2.png) [@cmaloney](https://discuss.python.org/u/cmaloney)\
**Post date:** [June 28, 2024, 10:07pm UTC](https://discuss.python.org/t/subprocess-use-vfork-escape-hatch-broken-fix-or-remove/56915/1 "2024-06-28T22:07:41Z")

</div>

I’m working to generalize the `strace` validation that vfork is used when expected ([cpython/Lib/test/test\_subprocess.py at main · python/cpython · GitHub](https://github.com/python/cpython/blob/main/Lib/test/test_subprocess.py#L3435-L3503), motivated by adding a test to [gh-120754: Reduce system calls in full-file readall case by cmaloney · Pull Request #120755 · python/cpython · GitHub](https://github.com/python/cpython/pull/120755)). Unfortunately with recent strace binaries that test hasn’t been working because `clone2` only exists on Linux ia64 and strace exits with an error when it is passed on x86\_64 which causes the test to be skipped). In fixing it I’ve found that at some point the `subprocess._USE_VFORK` flag stopped working[0].

Wondering whether there is a strong preference to fix the flag or to remove it + the documentation around it. The escape hatch was added in April 2022 and backported to Python 3.10 ([gh-91401: Add a failsafe way to disable vfork. by gpshead · Pull Request #91490 · python/cpython · GitHub](https://github.com/python/cpython/pull/91490) to resolve [potential undefined behavior with subprocess using vfork() on Linux? · Issue #91401 · python/cpython · GitHub](https://github.com/python/cpython/issues/91401))

@gpshead and @vstinner who worked on the escape hatch + strace test

[0]  
Sample code:

```python
import subprocess
subprocess._USE_VFORK = False
try:
    subprocess.check_call(
            ['/bin/true'], **dict())
except PermissionError:
    if not False:
        raise

```

command which can be run with subprocess (What the test runs):

```python
['/usr/bin/strace', '--trace=%process', 'python', '-X', 'faulthandler', '-I', '-c', "import subprocess\nsubprocess._USE_VFORK = False\ntry:\n subprocess.check_call(\n ['/bin/true'], **dict())\nexcept PermissionError:\n if not False:\n raise"]

```

```python
execve("<path>/python/build/python", ["<path>/pytho"..., "-X", "faulthandler", "-I", "-c", "import subprocess\nsubprocess._US"...], 0x7ffe3b1c5470 /* 65 vars */) = 0
clone3({flags=CLONE_VM|CLONE_VFORK|CLONE_CLEAR_SIGHAND, exit_signal=SIGCHLD, stack=0x79a0b6254000, stack_size=0x9000}, 88) = 260561
wait4(260561, [{WIFEXITED(s) && WEXITSTATUS(s) == 0}], 0, NULL) = 260561
--- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=260561, si_uid=1000, si_status=0, si_utime=0, si_stime=0} ---
exit_group(0) = ?

```

---

<div class="post-metadata">

**Author:** ![gpshead](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/gpshead/32/54_2.png) [@gpshead](https://discuss.python.org/u/gpshead)\
**Post date:** [June 29, 2024, 12:15am UTC](https://discuss.python.org/t/subprocess-use-vfork-escape-hatch-broken-fix-or-remove/56915/2 "2024-06-29T00:15:26Z")

</div>

Off the top of my head (which is full… so does that mean much?) – I’m not aware of anyone actually using the escape hatch.

We had concerns that someone may need it during the initial implementation, but does anyone have references to people or projects that found a practical need and are willing to share those publicly?

if it isn’t behaving right, that’s a sign that we aren’t really testing it reliably…

---

<div class="post-metadata">

**Author:** ![cmaloney](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/cmaloney/32/15851_2.png) [@cmaloney](https://discuss.python.org/u/cmaloney)\
**Post date:** [July 4, 2024, 10:44pm UTC](https://discuss.python.org/t/subprocess-use-vfork-escape-hatch-broken-fix-or-remove/56915/3 "2024-07-04T22:44:48Z")

</div>

Opened a PR to disable the \_USE\_VFORK flag: [gh-121381 Remove subprocess.\_USE\_VFORK escape hatch by cmaloney · Pull Request #121383 · python/cpython · GitHub](https://github.com/python/cpython/pull/121383)

Also have a PR for getting the test back to working and run by at least one CI bot: [GH-120754: Add a strace helper and test set of syscalls for open().read() by cmaloney · Pull Request #121143 · python/cpython · GitHub](https://github.com/python/cpython/pull/121143)
