Title: `asyncio.create_subprocess_shell` does not consistently result in negative `returncode` on signal termination · Issue #138234 · python/cpython · GitHub
Open Graph Title: `asyncio.create_subprocess_shell` does not consistently result in negative `returncode` on signal termination · Issue #138234 · python/cpython
X Title: `asyncio.create_subprocess_shell` does not consistently result in negative `returncode` on signal termination · Issue #138234 · python/cpython
Description: Bug report Bug description: The docs for returncode state the following: A negative value -N indicates that the child was terminated by signal N (POSIX only). which does not technically require, but strongly suggest that processes termin...
Open Graph Description: Bug report Bug description: The docs for returncode state the following: A negative value -N indicates that the child was terminated by signal N (POSIX only). which does not technically require, bu...
X Description: Bug report Bug description: The docs for returncode state the following: A negative value -N indicates that the child was terminated by signal N (POSIX only). which does not technically require, bu...
Opengraph URL: https://github.com/python/cpython/issues/138234
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"`asyncio.create_subprocess_shell` does not consistently result in negative `returncode` on signal termination","articleBody":"# Bug report\n\n### Bug description:\n\nThe [docs for `returncode`](https://docs.python.org/3.13/library/asyncio-subprocess.html#asyncio.subprocess.Process.returncode) state the following:\n\n\u003e A negative value `-N` indicates that the child was terminated by signal `N` (POSIX only).\n\nwhich does not technically require, but strongly suggest that processes terminated by signals will have a negative `returncode` 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 negative `returncode`s upon termination by signal in the docs and to adapt the code on non-conformant platforms accordingly.\n\nInterestingly, `asyncio.create_subprocess_exec` has the expected behavior of consistently negative `returncode`s on the tested platforms, which increases my suspicion that there is indeed undesired behavior involved. \n\n```python\nimport asyncio\n\n\nasync def repro():\n proc = await asyncio.create_subprocess_shell(\"./sigint.sh\")\n await proc.communicate()\n print(proc.returncode)\n assert proc.returncode == -2\n\n\nasyncio.run(repro())\n```\n\n`sigint.sh`:\n```sh\n#!/bin/sh\nkill -2 $$\n```\n\nI created a repo to show the differences in GitHub's CI: https://github.com/danielrainer/python_signal_returncode_repro/actions/runs/17310888203\n\n### CPython versions tested on:\n\n3.13, 3.12\n\n### Operating systems tested on:\n\nLinux, macOS\n\n\u003c!-- gh-linked-prs --\u003e\n### Linked PRs\n* gh-138536\n* gh-146254\n* gh-146255\n\u003c!-- /gh-linked-prs --\u003e\n","author":{"url":"https://github.com/danielrainer","@type":"Person","name":"danielrainer"},"datePublished":"2025-08-29T00:25:15.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":2},"url":"https://github.com/138234/cpython/issues/138234"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:952274bb-8ab3-1a93-191d-dd46bbe65298 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 9880:57C75:2FE1F3:43E76D:6A50F65D |
| html-safe-nonce | 1a7c95c5a66ee1da66ae91a13349b51c67246375196a71f691d026a2ca9027b0 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5ODgwOjU3Qzc1OjJGRTFGMzo0M0U3NkQ6NkE1MEY2NUQiLCJ2aXNpdG9yX2lkIjoiMzk2MzEyNjg4ODg2MDI4NDUwOSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | b5a516931d6d3d48cd5b34035ef0501f046eaa011dad252a3f813dc66382c3a1 |
| hovercard-subject-tag | issue:3365039129 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/138234/issue_layout |
| twitter:image | https://opengraph.githubassets.com/c14045c323bf688aabae77814bbb4892a20a6fd11a30d12d544c283a6586211f/python/cpython/issues/138234 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/c14045c323bf688aabae77814bbb4892a20a6fd11a30d12d544c283a6586211f/python/cpython/issues/138234 |
| og:image:alt | Bug report Bug description: The docs for returncode state the following: A negative value -N indicates that the child was terminated by signal N (POSIX only). which does not technically require, bu... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | danielrainer |
| hostname | github.com |
| expected-hostname | github.com |
| None | 5266e58c17a510c403505cc811606465e90a881d2007ee7df1c4800d5c659838 |
| turbo-cache-control | no-preview |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 8d836581d020676cc0ef4a83cd2fe17e4af02c3d |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width