GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Detect QEMU linux-user emulation in `subprocess._use_posix_spawn()` · Issue #131398 · python/cpython

Detect QEMU linux-user emulation in subprocess._use_posix_spawn() #131398

New issue
Copy link
New issue
Copy link
Open
Open
Detect QEMU linux-user emulation in subprocess._use_posix_spawn()#131398
Copy link
Labels
OS-unsupportedstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

Description

@andreas-schwab
andreas-schwab
opened on Mar 18, 2025
Issue body actions

The qemu linux-user emulation does not support CLONE_VFORK and emulates it
with a true fork. That breaks posix_spawn because it cannot report errors
back to the parent process. The subprocess modules should detect that is
it being executed in qemu linux-user emulation and return False in
_use_posix_spawn. One way to do that is to look for "uarch *: qemu" in
/proc/cpuinfo.

Activity

  1. picnixz
    added
    type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
    extension-modulesC modules in the Modules dirC modules in the Modules dir
    stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directory
    and removed
    extension-modulesC modules in the Modules dirC modules in the Modules dir
    on Mar 18, 2025
  2. picnixz
    changed the title [-]Do not use posix_spawn in qemu linux-user emulation[/-] [+]Detect QEMU linux-user emulation in `subprocess._use_posix_spawn()`[/+] on Mar 18, 2025
  3. picnixz
    added
    OS-unsupported
    on Mar 18, 2025
  4. github-project-automation
    added this to Unsupported platformson Mar 18, 2025
  5. vstinner commented on Mar 20, 2025

    @vstinner
    vstinner
    on Mar 20, 2025
    Member
    More actions

    How is it an issue to use vfork() if it's emulated with fork()? Is it a performance issue? Do you have examples of benchmark showing the performance problem?

  6. andreas-schwab commented on Mar 20, 2025

    @andreas-schwab
    andreas-schwab
    on Mar 20, 2025
    ContributorAuthor
    More actions

    Without a true vfork, the posix_spawn implementation in glibc cannot
    report a proper errno value for errors that happen in the child before
    execve.

    See https://lists.gnu.org/archive/html/qemu-devel/2025-03/msg04706.html
    for more information.

  7. vstinner commented on Mar 20, 2025

    @vstinner
    vstinner
    on Mar 20, 2025
    Member
    More actions

    cc @gpshead

  8. vstinner commented on Mar 20, 2025

    @vstinner
    vstinner
    on Mar 20, 2025
    Member
    More actions

    Without a true vfork, the posix_spawn implementation in glibc cannot report a proper errno value for errors that happen in the child before execve.

    Do you have an example to reproduce the issue?

  9. andreas-schwab commented on Mar 20, 2025

    @andreas-schwab
    andreas-schwab
    on Mar 20, 2025
    ContributorAuthor
    More actions

    It causes a failure while building the MozillaFirefox package:

    4:55.15 Traceback (most recent call last):
    4:55.16 File "/home/abuild/rpmbuild/BUILD/MozillaFirefox-136.0.1-build/firefox-136.0.1/security/nss/./coreconf/werror.py", line 80, in
    4:55.16 main()
    4:55.16 ~~~~^^
    4:55.16 File "/home/abuild/rpmbuild/BUILD/MozillaFirefox-136.0.1-build/firefox-136.0.1/security/nss/./coreconf/werror.py", line 10, in main
    4:55.16 cc_is_clang = 'clang' in subprocess.check_output(
    4:55.16 ~~~~~~~~~~~~~~~~~~~~~~~^
    4:55.16 [cc, '--version'], universal_newlines=True, stderr=sink)
    4:55.16 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    4:55.16 File "/usr/lib64/python3.13/subprocess.py", line 474, in check_output
    4:55.16 return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
    4:55.16 ~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    4:55.17 **kwargs).stdout
    4:55.17 ^^^^^^^^^
    4:55.17 File "/usr/lib64/python3.13/subprocess.py", line 579, in run
    4:55.17 raise CalledProcessError(retcode, process.args,
    4:55.17 output=stdout, stderr=stderr)
    4:55.17 subprocess.CalledProcessError: Command '['/usr/bin/ccache /usr/bin/gcc', '--version']' returned non-zero exit status 127.

    The issue here is that posix_spawn should have set errno to ENOENT.

    Also, the python testsuite tests this in test_subprocess.py.

  10. andreas-schwab commented on Mar 20, 2025

    @andreas-schwab
    andreas-schwab
    on Mar 20, 2025
    ContributorAuthor
    More actions

    For exmaple:

    FAIL: test_exception_bad_args_0 (test.test_subprocess.POSIXProcessTestCase.test_exception_bad_args_0)
    Test error in the child raised in the parent for a bad args[0].

    Traceback (most recent call last):
    File "/home/abuild/rpmbuild/BUILD/python313-3.13.2-build/Python-3.13.2/Lib/test/test_subprocess.py", line 1903, in test_exception_bad_args_0
    self.fail("Expected OSError: %s" % desired_exception)
    ~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    AssertionError: Expected OSError: [Errno 2] No such file or directory: '/_this/pa.th/does/not/exist'

  11. gpshead commented on Mar 20, 2025

    @gpshead
    gpshead
    on Mar 20, 2025
    Member
    More actions

    FWIW I agreee with the approach of detecting this unusual/incomplete environment and having _use_posix_spawn() return False there.

  12. vfazio commented on Apr 7, 2025

    @vfazio
    vfazio
    on Apr 7, 2025
    Contributor
    More actions

    Seems somewhat related: #129204. I ran into a similar scenario until i bumped QEMU to v7.2+

  13. vfazio commented on Apr 7, 2025

    @vfazio
    vfazio
    on Apr 7, 2025
    Contributor
    More actions

    Might also be worthwhile to not use posix_spawn if proc isn't mounted. As mentioned in the issue I linked, QEMU is sometimes run without proc or sys mounted due to limitations of the container environment so you may not even be able to query if you're running under emulation, in which case it may make sense to just assume we are.

    For now, there's at least a knob (#132184) that can be exported into the environment to force the code to not use posix_spawn.

  14. gpshead commented on Apr 7, 2025

    @gpshead
    gpshead
    on Apr 7, 2025
    Member
    More actions

    Saving some clicks, the undocumented knob added for CPython >=3.13.3 and >=3.14 is to set _PYTHON_SUBPROCESS_USE_POSIX_SPAWN=0 in your environment when you have an unusual environment that must not use it.

  15. felixonmars
    added a commit that references this issue on Oct 7, 2026

    addpatch: pre-commit 4.6.2-1

    f3502ed
  16. felixonmars
    added a commit that references this issue on Oct 16, 2026

    qemu-user-blacklist: add python-cmd2

    e43505f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    OS-unsupportedstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

    Projects

    • Unsupported platforms
      Status
      No status
      Show more project fields

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402520 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.