Title: test_forkserver_sigkill: join() can return before the child sets the event · Issue #160295 · python/cpython · GitHub
Open Graph Title: test_forkserver_sigkill: join() can return before the child sets the event · Issue #160295 · python/cpython
X Title: test_forkserver_sigkill: join() can return before the child sets the event · Issue #160295 · python/cpython
Description: Bug report Bug description: test_forkserver_sigkill failed once during a full ./python.exe -m test -j0 run on my machine (macOS 27.0.1, Apple M3, pydebug build of main at 1705e51). The load average was around 65 at the time. It passes wh...
Open Graph Description: Bug report Bug description: test_forkserver_sigkill failed once during a full ./python.exe -m test -j0 run on my machine (macOS 27.0.1, Apple M3, pydebug build of main at 1705e51). The load average...
X Description: Bug report Bug description: test_forkserver_sigkill failed once during a full ./python.exe -m test -j0 run on my machine (macOS 27.0.1, Apple M3, pydebug build of main at 1705e51). The load average...
Opengraph URL: https://github.com/python/cpython/issues/160295
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"test_forkserver_sigkill: join() can return before the child sets the event","articleBody":"# Bug report\n\n### Bug description:\n\n`test_forkserver_sigkill` failed once during a full `./python.exe -m test -j0` run on my machine (macOS 27.0.1, Apple M3, pydebug build of main at 1705e512b30). The load average was around 65 at the time. It passes when run on its own.\n\n```\ntest test.test_multiprocessing_forkserver.test_processes failed -- Traceback (most recent call last):\n File \"Lib/test/_test_multiprocessing.py\", line 1007, in test_forkserver_sigkill\n self.check_forkserver_death(signal.SIGKILL)\n File \"Lib/test/_test_multiprocessing.py\", line 997, in check_forkserver_death\n self.assertTrue(evt.is_set())\nAssertionError: False is not true\n```\n\n(paths shortened)\n\nThis is the same failure as gh-78221 (bpo-34040). It was worked around in 2018 by shortening the child's delay relative to the parent's sleep (07888e1cce), but the race is still there.\n\n`check_forkserver_death()` kills the forkserver right after starting the first process. After a SIGKILL, the forkserver can no longer report that child's exit status: `proc.join()` gets EOF on the status pipe, and `Popen.poll()` in `Lib/multiprocessing/popen_forkserver.py` sets `returncode` to 255 immediately. The child may still be running at that point. The test then checks `evt.is_set()`, which only passes if the child has set the event by then (within the 1 second sleep plus the time `proc2` takes). The next line already accepts exit code 255 for the case where the forkserver was killed.\n\nSIGINT is not affected: the forkserver ignores it, stays alive and reports the real exit code.\n\nTo reproduce it reliably, stop the first child with SIGSTOP for a few seconds after killing the forkserver:\n\n\u003cdetails>\n\u003csummary>Reproducer\u003c/summary>\n\n```python\nimport multiprocessing as mp, os, signal, threading, time\nfrom multiprocessing.forkserver import _forkserver\n\ndef sleep_and_set(evt, delay=0.0):\n time.sleep(delay)\n evt.set()\n\nif __name__ == '__main__':\n mp.set_start_method('forkserver')\n _forkserver.ensure_running()\n evt = mp.Event()\n proc = mp.Process(target=sleep_and_set, args=(evt, 0.5))\n proc.start()\n os.kill(_forkserver._forkserver_pid, signal.SIGKILL)\n # Simulate the child not getting CPU time for 3 seconds.\n os.kill(proc.pid, signal.SIGSTOP)\n threading.Timer(3.0, os.kill, (proc.pid, signal.SIGCONT)).start()\n time.sleep(1.0)\n proc.join()\n print(proc.exitcode, evt.is_set()) # 255 False\n print(evt.wait(60)) # True: the child did run, later\n```\n\n\u003c/details>\n\nWaiting for the event with a timeout, instead of checking it right after `join()`, fixes it.\n\nThe same code is in 3.13, 3.14 and 3.15.\n\n### CPython versions tested on:\n\nCPython main branch\n\n### Operating systems tested on:\n\nmacOS, Linux\n\n\n\u003c!-- gh-linked-prs -->\n### Linked PRs\n* gh-160296\n* gh-160508\n* gh-160509\n\u003c!-- /gh-linked-prs -->\n","author":{"url":"https://github.com/devdavidejesus","@type":"Person","name":"devdavidejesus"},"datePublished":"2026-10-22T18:30:33Z","url":"https://github.com/python/cpython/issues/160295"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| 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:50f2bc87-3e9b-89b3-fad5-f853ebc32423 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | DA5A:33E41:2D20A7:3BD563:6B023346 |
| html-safe-nonce | 64553c107044a7017c6c79fd5bc00912d1243fdfe8ead1458bc0078cb71df339 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEQTVBOjMzRTQxOjJEMjBBNzozQkQ1NjM6NkIwMjMzNDYiLCJ2aXNpdG9yX2lkIjoiOTAxMDk5ODU4MDMxMTM3MjYxNCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 9b47e06ef1a751349f5a2086ea72ce8331ad4f38b2a1111f62fabea8c8a22a38 |
| hovercard-subject-tag | issue:5985208409 |
| 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/160295/issue_layout |
| twitter:image | https://opengraph.githubassets.com/88f1f53fdba1e48e803a5612b82fad2d823d8ba2302da900630f351c660f6dbe/python/cpython/issues/160295 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/88f1f53fdba1e48e803a5612b82fad2d823d8ba2302da900630f351c660f6dbe/python/cpython/issues/160295 |
| og:image:alt | Bug report Bug description: test_forkserver_sigkill failed once during a full ./python.exe -m test -j0 run on my machine (macOS 27.0.1, Apple M3, pydebug build of main at 1705e51). The load average... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | devdavidejesus |
| hostname | github.com |
| expected-hostname | github.com |
| None | 87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456 |
| 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 | 423dbb54c5e7bfecc838eb387c1435eb3d0e760d |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width