Title: gh-133465: Efficient signal checks with detached thread state. by zackw · Pull Request #135358 · python/cpython · GitHub
Open Graph Title: gh-133465: Efficient signal checks with detached thread state. by zackw · Pull Request #135358 · python/cpython
X Title: gh-133465: Efficient signal checks with detached thread state. by zackw · Pull Request #135358 · python/cpython
Description: Add new C-API functions PyErr_CheckSignalsDetached and PyErr_AreSignalsPending. PyErr_CheckSignalsDetached can only be called by threads that don’t have an attached thread state. It does the same thing as PyErr_CheckSignals, except that it guarantees it will only reattach the supplied thread state if necessary in order to run signal handlers. (Also, it never runs the cycle collector.) PyErr_AreSignalsPending can be called with or without an attached thread state. It reports to its caller whether signals are pending, but never runs any handlers itself. Rationale: Compiled-code modules that implement time-consuming operations that don’t require manipulating Python objects, are supposed to call PyErr_CheckSignals frequently throughout each such operation, so that if the user interrupts the operation with control-C, it is canceled promptly. In the normal case where no signals are pending, PyErr_CheckSignals is cheap (two atomic memory operations); however, callers must have an attached thread state, and compiled-code modules that implement time-consuming operations are also supposed to detach their thread state during each such operation. The overhead of re-attaching a thread state in order to call PyErr_CheckSignals, and then releasing it again, sufficiently often for reasonable user responsiveness, can be substantial, particularly in traditional (non-free-threaded) builds. These new functions permit compiled-code modules to avoid that extra overhead. Issue: gh-133465 📚 Documentation preview 📚: https://cpython-previews--135358.org.readthedocs.build/en/135358/c-api/exceptions.html#c.PyErr_CheckSignalsDetached
Open Graph Description: Add new C-API functions PyErr_CheckSignalsDetached and PyErr_AreSignalsPending. PyErr_CheckSignalsDetached can only be called by threads that don’t have an attached thread state. It does the same ...
X Description: Add new C-API functions PyErr_CheckSignalsDetached and PyErr_AreSignalsPending. PyErr_CheckSignalsDetached can only be called by threads that don’t have an attached thread state. It does the same ...
Opengraph URL: https://github.com/python/cpython/pull/135358
X: @github
Domain: github.com
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:39f8ce02-5741-10fc-b939-4ee1b141e1fd |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | EA16:3F7BE4:364F3E:49F861:6A55950C |
| html-safe-nonce | 8a1493a3d6a679f1d86cc4aa971727939dd49ad07ac667c5bd6de49cbcedb0d5 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFQTE2OjNGN0JFNDozNjRGM0U6NDlGODYxOjZBNTU5NTBDIiwidmlzaXRvcl9pZCI6Ijc5ODQxNDE3NTYzNDU2MDI2OCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 79431ad8849a92c72bbc70ed3c9e6fda0b778a3988f23d518f5bcee72a041cdd |
| hovercard-subject-tag | pull_request:2582097854 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,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/python/cpython/pull/135358/files |
| twitter:image | https://avatars.githubusercontent.com/u/325899?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/325899?s=400&v=4 |
| og:image:alt | Add new C-API functions PyErr_CheckSignalsDetached and PyErr_AreSignalsPending. PyErr_CheckSignalsDetached can only be called by threads that don’t have an attached thread state. It does the same ... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | b5665c84831ed9ac4fb79519c16c9c5580ba8092fb8bb6e3e72972ec7197348e |
| turbo-cache-control | no-preview |
| diff-view | unified |
| 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 full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | aa21baa44893467b0b640d0300538f84ca8c475b |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width