Title: _test_multiprocessing._kill_process() uses a fixed 10 s alarm, failing on slow builds · Issue #157184 · python/cpython · GitHub
Open Graph Title: _test_multiprocessing._kill_process() uses a fixed 10 s alarm, failing on slow builds · Issue #157184 · python/cpython
X Title: _test_multiprocessing._kill_process() uses a fixed 10 s alarm, failing on slow builds · Issue #157184 · python/cpython
Description: Bug report Bug description: _test_multiprocessing._kill_process() guards the join() of the killed child with a SIGALRM fixed at 10 seconds: if hasattr(signal, 'alarm'): # On the Gentoo buildbot waitpid() often seems to block forever. # W...
Open Graph Description: Bug report Bug description: _test_multiprocessing._kill_process() guards the join() of the killed child with a SIGALRM fixed at 10 seconds: if hasattr(signal, 'alarm'): # On the Gentoo buildbot wai...
X Description: Bug report Bug description: _test_multiprocessing._kill_process() guards the join() of the killed child with a SIGALRM fixed at 10 seconds: if hasattr(signal, 'alarm'): # On the Gentoo buil...
Opengraph URL: https://github.com/python/cpython/issues/157184
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"_test_multiprocessing._kill_process() uses a fixed 10 s alarm, failing on slow builds","articleBody":"# Bug report\n\n### Bug description:\n\n`_test_multiprocessing._kill_process()` guards the `join()` of the killed child with a `SIGALRM` fixed at 10 seconds:\n\n```python\n if hasattr(signal, 'alarm'):\n # On the Gentoo buildbot waitpid() often seems to block forever.\n # We use alarm() to interrupt it if it blocks for too long.\n def handler(*args):\n raise RuntimeError('join took too long: %s' % p)\n old_handler = signal.signal(signal.SIGALRM, handler)\n try:\n signal.alarm(10)\n self.assertEqual(join(), None)\n```\n\nThe alarm is meant to turn a blocked `waitpid()` into a readable error instead of a hang. But the value has been a literal `10` since it was added in 2013 (cc5c728513a), so on a build slow enough that reaping the child legitimately takes longer than ten seconds, it fires on a healthy run and fails the test.\n\nThat happened on the \"Sanitizers / UBSan\" job of 57594aae5e: https://github.com/python/cpython/actions/runs/34016012199/job/101439811595\n\n```\nERROR: test_interrupt (test.test_multiprocessing_fork.test_processes.WithProcessesTestProcess.test_interrupt)\n File \".../Lib/test/_test_multiprocessing.py\", line 651, in test_interrupt\n exitcode = self._kill_process(multiprocessing.Process.interrupt)\n File \".../Lib/test/_test_multiprocessing.py\", line 632, in _kill_process\n self.assertEqual(join(), None)\n File \".../Lib/multiprocessing/popen_fork.py\", line 28, in poll\n pid, sts = os.waitpid(self.pid, flag)\n File \".../Lib/test/_test_multiprocessing.py\", line 628, in handler\n raise RuntimeError('join took too long: %s' % p)\nRuntimeError: join took too long: \u003cProcess name='Process-162' pid=18960 parent=17748 started daemon>\n```\n\nThe traceback shows the alarm interrupting `os.waitpid()`, which is the normal path, not a hang.\n\n`test.support` already provides timeouts for this, and regrtest scales them for slow builds (`Lib/test/libregrtest/setup.py` raises `SHORT_TIMEOUT` and `LONG_TIMEOUT` from `--timeout`). `LONG_TIMEOUT` is documented for exactly this use:\n\n```\n# Timeout in seconds to detect when a test hangs.\n#\n# It is long enough to reduce the risk of test failure on the slowest Python\n# buildbots. It should not be used to mark a test as failed if the test takes\n# \"too long\".\n```\n\nand the comment on `SHORT_TIMEOUT` says \"If a test using SHORT_TIMEOUT starts to fail randomly on slow buildbots, use LONG_TIMEOUT instead\". The same `_kill_process()` already uses `support.SHORT_TIMEOUT` a few lines above, for the event wait.\n\n### Reproducer\n\nThe alarm fires whenever the child takes longer than ten seconds to be reaped. Replicating the alarm block with a child that is slow to exit:\n\n```python\nimport multiprocessing, signal, sys, time\n\ndef child(event, delay):\n def slow_exit(*args):\n time.sleep(delay) # a loaded machine: the child is slow to die\n sys.exit(0)\n signal.signal(signal.SIGINT, slow_exit)\n event.set()\n time.sleep(100)\n\nif __name__ == '__main__':\n alarm_secs, delay = int(sys.argv[1]), float(sys.argv[2])\n event = multiprocessing.Event()\n p = multiprocessing.Process(target=child, args=(event, delay))\n p.daemon = True\n p.start()\n event.wait(30)\n p.interrupt()\n\n def handler(*args):\n raise RuntimeError('join took too long: %s' % p)\n signal.signal(signal.SIGALRM, handler)\n try:\n signal.alarm(alarm_secs)\n p.join()\n print(\"join returned, exitcode\", p.exitcode)\n except RuntimeError as exc:\n print(\"RuntimeError:\", exc)\n finally:\n signal.alarm(0)\n```\n\n```\n$ ./python mp_alarm.py 10 12\nRuntimeError: join took too long: \u003cProcess name='Process-1' pid=13882 parent=13880 started daemon>\n$ ./python mp_alarm.py 300 12\njoin returned, exitcode 0\n```\n\nThe four tests that go through `_kill_process()` (`test_interrupt`, `test_interrupt_no_handler`, `test_terminate`, `test_kill`) are affected, in every start-method variant.\n\n### CPython versions tested on:\n\nCPython main branch\n\n### Operating systems tested on:\n\nLinux (CI), macOS (reproducer)\n\n\n\u003c!-- gh-linked-prs -->\n### Linked PRs\n* gh-157185\n\u003c!-- /gh-linked-prs -->\n","author":{"url":"https://github.com/iamsharduld","@type":"Person","name":"iamsharduld"},"datePublished":"2026-09-08T13:53:47Z","url":"https://github.com/python/cpython/issues/157184"}
| 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:66b59eb3-a0ec-9527-7f25-f6ce4b207fc7 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 9924:28A483:165CEC9:1D9B8AD:6B020235 |
| html-safe-nonce | d047a09568fa7de1fc2c7e43082b71990853752678ef7691d66452623d8daba7 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5OTI0OjI4QTQ4MzoxNjVDRUM5OjFEOUI4QUQ6NkIwMjAyMzUiLCJ2aXNpdG9yX2lkIjoiOTE3ODQ0MDA3MDc3OTI0MTAxMyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | d374dd936000fadb4e9c5d1cbae11433172d4de18ce719778f19525c4353c1fb |
| hovercard-subject-tag | issue:5387611903 |
| 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/157184/issue_layout |
| twitter:image | https://opengraph.githubassets.com/d30c493ba08be9ac47a2ccddff8c7f3dff04d732993f128df29be3a506e21e53/python/cpython/issues/157184 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/d30c493ba08be9ac47a2ccddff8c7f3dff04d732993f128df29be3a506e21e53/python/cpython/issues/157184 |
| og:image:alt | Bug report Bug description: _test_multiprocessing._kill_process() guards the join() of the killed child with a SIGALRM fixed at 10 seconds: if hasattr(signal, 'alarm'): # On the Gentoo buildbot wai... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | iamsharduld |
| 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