René's URL Explorer Experiment


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

direct link

Domain: github.com

route-pattern/:user_id/:repository/pull/:id/files(.:format)
route-controllerpull_requests
route-actionfiles
fetch-noncev2:dc518195-4a4b-0d6d-cc2f-0a924cb7a9d9
current-catalog-service-hashae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b
request-idE514:24CD64:113110C:17093CD:696AD2CF
html-safe-nonce4dd0438a6801f9ba1bf8c9ff1d2035d8ee54ee56b3d7cf360047e5800282f26e
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFNTE0OjI0Q0Q2NDoxMTMxMTBDOjE3MDkzQ0Q6Njk2QUQyQ0YiLCJ2aXNpdG9yX2lkIjoiNzYyMzE4MzMwNDIxNDg5MzI2MyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmac915469237da47c6a23039393936a8200c8688cf5e58cf8c41ced6bb4bb1d1d2d
hovercard-subject-tagpull_request:2782433673
github-keyboard-shortcutsrepository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///pull_requests/show/files
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/python/cpython/pull/138229/files
twitter:imagehttps://avatars.githubusercontent.com/u/2095011?s=400&v=4
twitter:cardsummary_large_image
og:imagehttps://avatars.githubusercontent.com/u/2095011?s=400&v=4
og:image:altThis 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_nameGitHub
og:typeobject
hostnamegithub.com
expected-hostnamegithub.com
Nonec785f4ce187e9e7331257791b36ddee01625bb8e292a9b4fe2c16d4c006abf5d
turbo-cache-controlno-preview
diff-viewunified
go-importgithub.com/python/cpython git https://github.com/python/cpython.git
octolytics-dimension-user_id1525981
octolytics-dimension-user_loginpython
octolytics-dimension-repository_id81598961
octolytics-dimension-repository_nwopython/cpython
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id81598961
octolytics-dimension-repository_network_root_nwopython/cpython
turbo-body-classeslogged-out env-production page-responsive full-width
disable-turbotrue
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
releasec718a376fcf780eb22089171adb84a543f660bf7
ui-targetcanary-2
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/python/cpython/pull/138229/files#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fpull%2F138229%2Ffiles
GitHub CopilotWrite better code with AIhttps://github.com/features/copilot
GitHub SparkBuild and deploy intelligent appshttps://github.com/features/spark
GitHub ModelsManage and compare promptshttps://github.com/features/models
MCP RegistryNewIntegrate external toolshttps://github.com/mcp
ActionsAutomate any workflowhttps://github.com/features/actions
CodespacesInstant dev environmentshttps://github.com/features/codespaces
IssuesPlan and track workhttps://github.com/features/issues
Code ReviewManage code changeshttps://github.com/features/code-review
GitHub Advanced SecurityFind and fix vulnerabilitieshttps://github.com/security/advanced-security
Code securitySecure your code as you buildhttps://github.com/security/advanced-security/code-security
Secret protectionStop leaks before they starthttps://github.com/security/advanced-security/secret-protection
Why GitHubhttps://github.com/why-github
Documentationhttps://docs.github.com
Bloghttps://github.blog
Changeloghttps://github.blog/changelog
Marketplacehttps://github.com/marketplace
View all featureshttps://github.com/features
Enterpriseshttps://github.com/enterprise
Small and medium teamshttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
App Modernizationhttps://github.com/solutions/use-case/app-modernization
DevSecOpshttps://github.com/solutions/use-case/devsecops
DevOpshttps://github.com/solutions/use-case/devops
CI/CDhttps://github.com/solutions/use-case/ci-cd
View all use caseshttps://github.com/solutions/use-case
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
View all industrieshttps://github.com/solutions/industry
View all solutionshttps://github.com/solutions
AIhttps://github.com/resources/articles?topic=ai
Software Developmenthttps://github.com/resources/articles?topic=software-development
DevOpshttps://github.com/resources/articles?topic=devops
Securityhttps://github.com/resources/articles?topic=security
View all topicshttps://github.com/resources/articles
Customer storieshttps://github.com/customer-stories
Events & webinarshttps://github.com/resources/events
Ebooks & reportshttps://github.com/resources/whitepapers
Business insightshttps://github.com/solutions/executive-insights
GitHub Skillshttps://skills.github.com
Documentationhttps://docs.github.com
Customer supporthttps://support.github.com
Community forumhttps://github.com/orgs/community/discussions
Trust centerhttps://github.com/trust-center
Partnershttps://github.com/partners
GitHub SponsorsFund open source developershttps://github.com/sponsors
Security Labhttps://securitylab.github.com
Maintainer Communityhttps://maintainers.github.com
Acceleratorhttps://github.com/accelerator
Archive Programhttps://archiveprogram.github.com
Topicshttps://github.com/topics
Trendinghttps://github.com/trending
Collectionshttps://github.com/collections
Enterprise platformAI-powered developer platformhttps://github.com/enterprise
GitHub Advanced SecurityEnterprise-grade security featureshttps://github.com/security/advanced-security
Copilot for BusinessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/premium-support
Pricinghttps://github.com/pricing
Search syntax tipshttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
documentationhttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fpull%2F138229%2Ffiles
Sign up https://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fpull_requests%2Fshow%2Ffiles&source=header-repo&source_repo=python%2Fcpython
Reloadhttps://github.com/python/cpython/pull/138229/files
Reloadhttps://github.com/python/cpython/pull/138229/files
Reloadhttps://github.com/python/cpython/pull/138229/files
python https://github.com/python
cpythonhttps://github.com/python/cpython
Please reload this pagehttps://github.com/python/cpython/pull/138229/files
Notifications https://github.com/login?return_to=%2Fpython%2Fcpython
Fork 33.9k https://github.com/login?return_to=%2Fpython%2Fcpython
Star 71.1k https://github.com/login?return_to=%2Fpython%2Fcpython
Code https://github.com/python/cpython
Issues 5k+ https://github.com/python/cpython/issues
Pull requests 2.1k https://github.com/python/cpython/pulls
Actions https://github.com/python/cpython/actions
Projects 31 https://github.com/python/cpython/projects
Security Uh oh! There was an error while loading. Please reload this page. https://github.com/python/cpython/security
Please reload this pagehttps://github.com/python/cpython/pull/138229/files
Insights https://github.com/python/cpython/pulse
Code https://github.com/python/cpython
Issues https://github.com/python/cpython/issues
Pull requests https://github.com/python/cpython/pulls
Actions https://github.com/python/cpython/actions
Projects https://github.com/python/cpython/projects
Security https://github.com/python/cpython/security
Insights https://github.com/python/cpython/pulse
Sign up for GitHub https://github.com/signup?return_to=%2Fpython%2Fcpython%2Fissues%2Fnew%2Fchoose
terms of servicehttps://docs.github.com/terms
privacy statementhttps://docs.github.com/privacy
Sign inhttps://github.com/login?return_to=%2Fpython%2Fcpython%2Fissues%2Fnew%2Fchoose
kumaraditya303https://github.com/kumaraditya303
python:mainhttps://github.com/python/cpython/tree/main
yoney:ft_cprofilehttps://github.com/yoney/cpython/tree/ft_cprofile
Conversation 11 https://github.com/python/cpython/pull/138229
Commits 5 https://github.com/python/cpython/pull/138229/commits
Checks 47 https://github.com/python/cpython/pull/138229/checks
Files changed 4 https://github.com/python/cpython/pull/138229/files
gh-116738: Make cProfile module thread-safe https://github.com/python/cpython/pull/138229/files#top
Show all changes 5 commits https://github.com/python/cpython/pull/138229/files
3bb0e14 gh-116738: Make cProfile module thread-safe yoney Aug 25, 2025 https://github.com/python/cpython/pull/138229/commits/3bb0e1496aa4d3f20ab197451ca0a7943bf16196
d4d4d51 gh-116738: Remove the unnecessary critical_section parameter yoney Sep 5, 2025 https://github.com/python/cpython/pull/138229/commits/d4d4d51cb64c1549512221c0d553c24f6f16ae8c
42942c5 gh-116738: Remove the critical_section for profiler_init() yoney Sep 5, 2025 https://github.com/python/cpython/pull/138229/commits/42942c503e13fdbbdbde3406b56736ada61420de
0f0a658 Merge branch 'main' into ft_cprofile kumaraditya303 Sep 6, 2025 https://github.com/python/cpython/pull/138229/commits/0f0a658d7c96535a777934a359d5616165c8fd12
e6eeb1e Update Misc/NEWS.d/next/Core_and_Builtins/2025-08-28-09-29-46.gh-issu… kumaraditya303 Sep 6, 2025 https://github.com/python/cpython/pull/138229/commits/e6eeb1ed5619d7634fd78d3cb2896b66b9f3d871
Clear filters https://github.com/python/cpython/pull/138229/files
Please reload this pagehttps://github.com/python/cpython/pull/138229/files
Please reload this pagehttps://github.com/python/cpython/pull/138229/files
test_cprofile.py https://github.com/python/cpython/pull/138229/files#diff-b1d14835691fabfda1928952e9e6ccbacfbf80a7619c801512c5e4be41e6071d
2025-08-28-09-29-46.gh-issue-116738.yLZJpV.rst https://github.com/python/cpython/pull/138229/files#diff-7214256ed7c1a6632fa7a837e0fa31bee2fd958dbb7eef88b5d096edec5166e6
_lsprof.c https://github.com/python/cpython/pull/138229/files#diff-fe854c1e90974a430c6672f28fcf6e470b6be183d515b851367581fed030b6c3
_lsprof.c.h https://github.com/python/cpython/pull/138229/files#diff-6e4105aab212843ef2b2815384ad2f0b70e7e66d3b7b3843c4deda5adb06009a
Lib/test/test_free_threading/test_cprofile.pyhttps://github.com/python/cpython/pull/138229/files#diff-b1d14835691fabfda1928952e9e6ccbacfbf80a7619c801512c5e4be41e6071d
View file https://github.com/yoney/cpython/blob/e6eeb1ed5619d7634fd78d3cb2896b66b9f3d871/Lib/test/test_free_threading/test_cprofile.py
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/cpython/pull/138229/{{ revealButtonHref }}
Misc/NEWS.d/next/Core_and_Builtins/2025-08-28-09-29-46.gh-issue-116738.yLZJpV.rsthttps://github.com/python/cpython/pull/138229/files#diff-7214256ed7c1a6632fa7a837e0fa31bee2fd958dbb7eef88b5d096edec5166e6
View file https://github.com/yoney/cpython/blob/e6eeb1ed5619d7634fd78d3cb2896b66b9f3d871/Misc/NEWS.d/next/Core_and_Builtins/2025-08-28-09-29-46.gh-issue-116738.yLZJpV.rst
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/cpython/pull/138229/{{ revealButtonHref }}
Modules/_lsprof.chttps://github.com/python/cpython/pull/138229/files#diff-fe854c1e90974a430c6672f28fcf6e470b6be183d515b851367581fed030b6c3
View file https://github.com/yoney/cpython/blob/e6eeb1ed5619d7634fd78d3cb2896b66b9f3d871/Modules/_lsprof.c
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/cpython/pull/138229/{{ revealButtonHref }}
https://github.com/python/cpython/pull/138229/files#diff-fe854c1e90974a430c6672f28fcf6e470b6be183d515b851367581fed030b6c3
https://github.com/python/cpython/pull/138229/files#diff-fe854c1e90974a430c6672f28fcf6e470b6be183d515b851367581fed030b6c3
https://github.com/python/cpython/pull/138229/files#diff-fe854c1e90974a430c6672f28fcf6e470b6be183d515b851367581fed030b6c3
https://github.com/python/cpython/pull/138229/files#diff-fe854c1e90974a430c6672f28fcf6e470b6be183d515b851367581fed030b6c3
https://github.com/python/cpython/pull/138229/files#diff-fe854c1e90974a430c6672f28fcf6e470b6be183d515b851367581fed030b6c3
https://github.com/python/cpython/pull/138229/files#diff-fe854c1e90974a430c6672f28fcf6e470b6be183d515b851367581fed030b6c3
https://github.com/python/cpython/pull/138229/files#diff-fe854c1e90974a430c6672f28fcf6e470b6be183d515b851367581fed030b6c3
https://github.com/python/cpython/pull/138229/files#diff-fe854c1e90974a430c6672f28fcf6e470b6be183d515b851367581fed030b6c3
https://github.com/python/cpython/pull/138229/files#diff-fe854c1e90974a430c6672f28fcf6e470b6be183d515b851367581fed030b6c3
https://github.com/python/cpython/pull/138229/files#diff-fe854c1e90974a430c6672f28fcf6e470b6be183d515b851367581fed030b6c3
https://github.com/python/cpython/pull/138229/files#diff-fe854c1e90974a430c6672f28fcf6e470b6be183d515b851367581fed030b6c3
https://github.com/python/cpython/pull/138229/files#diff-fe854c1e90974a430c6672f28fcf6e470b6be183d515b851367581fed030b6c3
https://github.com/python/cpython/pull/138229/files#diff-fe854c1e90974a430c6672f28fcf6e470b6be183d515b851367581fed030b6c3
https://github.com/python/cpython/pull/138229/files#diff-fe854c1e90974a430c6672f28fcf6e470b6be183d515b851367581fed030b6c3
https://github.com/python/cpython/pull/138229/files#diff-fe854c1e90974a430c6672f28fcf6e470b6be183d515b851367581fed030b6c3
https://github.com/python/cpython/pull/138229/files#diff-fe854c1e90974a430c6672f28fcf6e470b6be183d515b851367581fed030b6c3
https://github.com/python/cpython/pull/138229/files#diff-fe854c1e90974a430c6672f28fcf6e470b6be183d515b851367581fed030b6c3
https://github.com/python/cpython/pull/138229/files#diff-fe854c1e90974a430c6672f28fcf6e470b6be183d515b851367581fed030b6c3
https://github.com/python/cpython/pull/138229/files#diff-fe854c1e90974a430c6672f28fcf6e470b6be183d515b851367581fed030b6c3
https://github.com/python/cpython/pull/138229/files#diff-fe854c1e90974a430c6672f28fcf6e470b6be183d515b851367581fed030b6c3
https://github.com/python/cpython/pull/138229/files#diff-fe854c1e90974a430c6672f28fcf6e470b6be183d515b851367581fed030b6c3
Modules/clinic/_lsprof.c.hhttps://github.com/python/cpython/pull/138229/files#diff-6e4105aab212843ef2b2815384ad2f0b70e7e66d3b7b3843c4deda5adb06009a
View file https://github.com/yoney/cpython/blob/e6eeb1ed5619d7634fd78d3cb2896b66b9f3d871/Modules/clinic/_lsprof.c.h
Open in desktop https://desktop.github.com
how customized files appear on GitHubhttps://docs.github.com/github/administering-a-repository/customizing-how-changed-files-appear-on-github
Please reload this pagehttps://github.com/python/cpython/pull/138229/files
Please reload this pagehttps://github.com/python/cpython/pull/138229/files
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.