Title: gh-116738: Make cProfile module thread-safe by yoney · Pull Request #138229 · python/cpython · GitHub
Open Graph Title: gh-116738: Make cProfile module thread-safe by yoney · Pull Request #138229 · python/cpython
X Title: gh-116738: Make cProfile module thread-safe by yoney · Pull Request #138229 · python/cpython
Description: This change uses critical sections to make cProfile (_lsprof) thread-safe when the GIL is disabled. It does this by applying the @critical_section clinic directive to ProfilerObject. Protecting ProfilerObject prevents crashes, and the thread sanitizer does not report errors for the new FT test. However, the stats still show incorrect recursive call information. ncalls tottime percall cumtime percall filename:lineno(function) 10000/538 0.085 0.000 0.186 0.000 {method 'insert' of 'list' objects} This happens because of limitations in the cProfile module, and these issues are not directly related to the FT Python build. By adjusting sys.setswitchinterval(), you can see similar incorrect recursive call reports even in a non-FT Python build. This is a quick fix to prevent crashes. It is also a request for comments on whether we should make bigger changes to the cProfile module to handle multithreading better, such as collecting profile data per thread. cc: @mpage, @colesbury, @Yhg1s Issue: gh-116738
Open Graph Description: This change uses critical sections to make cProfile (_lsprof) thread-safe when the GIL is disabled. It does this by applying the @critical_section clinic directive to ProfilerObject. Protecting Pro...
X Description: This change uses critical sections to make cProfile (_lsprof) thread-safe when the GIL is disabled. It does this by applying the @critical_section clinic directive to ProfilerObject. Protecting Pro...
Opengraph URL: https://github.com/python/cpython/pull/138229
X: @github
Domain: github.com
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:dc518195-4a4b-0d6d-cc2f-0a924cb7a9d9 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | E514:24CD64:113110C:17093CD:696AD2CF |
| html-safe-nonce | 4dd0438a6801f9ba1bf8c9ff1d2035d8ee54ee56b3d7cf360047e5800282f26e |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFNTE0OjI0Q0Q2NDoxMTMxMTBDOjE3MDkzQ0Q6Njk2QUQyQ0YiLCJ2aXNpdG9yX2lkIjoiNzYyMzE4MzMwNDIxNDg5MzI2MyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 915469237da47c6a23039393936a8200c8688cf5e58cf8c41ced6bb4bb1d1d2d |
| hovercard-subject-tag | pull_request:2782433673 |
| 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/138229/files |
| twitter:image | https://avatars.githubusercontent.com/u/2095011?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/2095011?s=400&v=4 |
| og:image:alt | This change uses critical sections to make cProfile (_lsprof) thread-safe when the GIL is disabled. It does this by applying the @critical_section clinic directive to ProfilerObject. Protecting Pro... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | c785f4ce187e9e7331257791b36ddee01625bb8e292a9b4fe2c16d4c006abf5d |
| 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 | c718a376fcf780eb22089171adb84a543f660bf7 |
| ui-target | canary-2 |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width