Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

asyncio.create_subprocess_shell does not consistently result in negativereturncode on signal termination #138234

Closed
Labels
stdlibStandard Library Python modules in the Lib/ directorytopic-asynciotype-bugAn unexpected behavior, bug, or error
@danielrainer

Description

@danielrainer

Bug report

Bug description:

Thedocs forreturncode state the following:

A negative value-N indicates that the child was terminated by signalN (POSIX only).

which does not technically require, but strongly suggest that processes terminated by signals will have a negativereturncode corresponding to the signal. On some platforms (observed on Arch Linux and macOS, both using Python 3.13.7), this does indeed seem to be the case. On others it is not. The observed counterexample is Ubuntu using Python 3.12.3. There,returncode seems to be set to 128 + signal value. Technically, this does not violate the documented behavior, but it is very surprising. If that is intended behavior, the docs deserve a clear warning. My preference would be to mandate negativereturncodes upon termination by signal in the docs and to adapt the code on non-conformant platforms accordingly.

Interestingly,asyncio.create_subprocess_exec has the expected behavior of consistently negativereturncodes on the tested platforms, which increases my suspicion that there is indeed undesired behavior involved.

importasyncioasyncdefrepro():proc=awaitasyncio.create_subprocess_shell("./sigint.sh")awaitproc.communicate()print(proc.returncode)assertproc.returncode==-2asyncio.run(repro())

sigint.sh:

#!/bin/shkill -2$$

I created a repo to show the differences in GitHub's CI:https://github.com/danielrainer/python_signal_returncode_repro/actions/runs/17310888203

CPython versions tested on:

3.13, 3.12

Operating systems tested on:

Linux, macOS

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibStandard Library Python modules in the Lib/ directorytopic-asynciotype-bugAn unexpected behavior, bug, or error

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2026 Movatter.jp