René's URL Explorer Experiment


Title: Add c-api to set callback function on enter and exit of PyContext · Issue #119333 · python/cpython · GitHub

Open Graph Title: Add c-api to set callback function on enter and exit of PyContext · Issue #119333 · python/cpython

X Title: Add c-api to set callback function on enter and exit of PyContext · Issue #119333 · python/cpython

Description: Feature or enhancement Proposal: In python every time a context is switched, two c-api are called. PyContext_Enter(PyObject *); PyContext_Exit(PyObject *); I need a way to know when those api's are called on a context. The purpose is tha...

Open Graph Description: Feature or enhancement Proposal: In python every time a context is switched, two c-api are called. PyContext_Enter(PyObject *); PyContext_Exit(PyObject *); I need a way to know when those api's are...

X Description: Feature or enhancement Proposal: In python every time a context is switched, two c-api are called. PyContext_Enter(PyObject *); PyContext_Exit(PyObject *); I need a way to know when those api's...

Opengraph URL: https://github.com/python/cpython/issues/119333

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Add c-api to set callback function on enter and exit of PyContext","articleBody":"# Feature or enhancement\r\n\r\n### Proposal:\r\n\r\nIn python every time a context is switched, two c-api are called. \r\n```\r\nPyContext_Enter(PyObject *);\r\nPyContext_Exit(PyObject *);\r\n```\r\nI need a way to know when those api's are called on a context.   The purpose is that at Meta we have a similar system to `contextvars` in C++ called `folly::requestcontext`.   When the python context switches we need to inform C++ to swap its active context.   Right now we have been carry forward patches to Asyncio.Task to do this on the `_step()` since way back in py3.6 which is generally the wrong place to do it. \r\n\r\nThere is prior art in #91054 which provides watching creation/destruction of Code objects.  The proposed solution would mirror that functionality closely. \r\n\r\n### Has this already been discussed elsewhere?\r\n\r\nI have already discussed this feature proposal on Discourse\r\n\r\n### Links to previous discussion of this feature:\r\n\r\nhttps://discuss.python.org/t/request-can-we-get-a-c-api-hook-into-pycontext-enter-and-pycontext-exit/51730\r\n\r\nThere was an in person meeting between @gvanrossum, @itamaro and myself where we discussed the plausibility of this feature request. \r\n\r\n\u003c!-- gh-linked-prs -->\r\n### Linked PRs\r\n* gh-119335\r\n* gh-124444\n* gh-124737\n* gh-124741\n* gh-124773\n* gh-124774\n* gh-124776\n\u003c!-- /gh-linked-prs -->\r\n","author":{"url":"https://github.com/fried","@type":"Person","name":"fried"},"datePublished":"2024-05-21T17:49:48Z","url":"https://github.com/python/cpython/issues/119333"}

react-profiling0
react-import-mapreact,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-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:e1e6c5ce-f0f8-4cfb-f2ea-47ba24ee10e1
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idC670:1F68:193D938:217CEE6:6B023680
html-safe-nonce29b5d1f5ddc2bba4ae01875d307be5441243f420161964440f42772291fb81f4
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDNjcwOjFGNjg6MTkzRDkzODoyMTdDRUU2OjZCMDIzNjgwIiwidmlzaXRvcl9pZCI6IjExMzA3OTE3NjA0MjM5NTgxNDUiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmacb30c49c7627538e7e97be1e737db767e9b2b1d97af3f71eb725023ddd14ecf4f
hovercard-subject-tagissue:2308806728
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/119333/issue_layout
twitter:imagehttps://opengraph.githubassets.com/ad9fb2554f927e5dca679c188bea82d78fb191b055aaab8526e1fd88dd159833/python/cpython/issues/119333
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/ad9fb2554f927e5dca679c188bea82d78fb191b055aaab8526e1fd88dd159833/python/cpython/issues/119333
og:image:altFeature or enhancement Proposal: In python every time a context is switched, two c-api are called. PyContext_Enter(PyObject *); PyContext_Exit(PyObject *); I need a way to know when those api's are...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamefried
hostnamegithub.com
expected-hostnamegithub.com
None87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456
turbo-cache-controlno-preview
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
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release423dbb54c5e7bfecc838eb387c1435eb3d0e760d
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/python/cpython/issues/119333#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fissues%2F119333
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
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
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://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/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fissues%2F119333
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=python%2Fcpython
Reloadhttps://github.com/python/cpython/issues/119333
Reloadhttps://github.com/python/cpython/issues/119333
Reloadhttps://github.com/python/cpython/issues/119333
pythonhttps://github.com/python
cpythonhttps://github.com/python/cpython
Codehttps://github.com/python/cpython
Issues5k+ (5k+)https://github.com/python/cpython/issues
Pull requests2.4k (2.4k)https://github.com/python/cpython/pulls
Actionshttps://github.com/python/cpython/actions
Projectshttps://github.com/python/cpython/projects
Security and qualityhttps://github.com/python/cpython/security
Insightshttps://github.com/python/cpython/insights
https://github.com/python/cpython
New issuehttps://github.com/login?return_to=https://github.com/python/cpython/issues/119333
New issuehttps://github.com/login?return_to=https://github.com/python/cpython/issues/119333
Add c-api to set callback function on enter and exit of PyContexthttps://github.com/python/cpython/issues/119333#top
topic-C-APIhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22topic-C-API%22
type-featureA feature request or enhancementhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-feature%22
https://github.com/fried
friedhttps://github.com/fried
on May 21, 2024https://github.com/python/cpython/issues/119333#issue-2308806728
#91054https://github.com/python/cpython/issues/91054
https://discuss.python.org/t/request-can-we-get-a-c-api-hook-into-pycontext-enter-and-pycontext-exit/51730https://discuss.python.org/t/request-can-we-get-a-c-api-hook-into-pycontext-enter-and-pycontext-exit/51730
@gvanrossumhttps://github.com/gvanrossum
@itamarohttps://github.com/itamaro
gh-119333: Add c-api to have contextvar enter/exit callbacks #119335https://github.com/python/cpython/pull/119335
gh-119333: PyContext watchers notify get interp from tstate #124444https://github.com/python/cpython/pull/124444
gh-124872: Change PyContext_WatchCallback to take PyObject #124737https://github.com/python/cpython/pull/124737
gh-124872: Back up exception before calling PyContext_WatchCallback #124741https://github.com/python/cpython/pull/124741
gh-124872: Refine contextvars documentation #124773https://github.com/python/cpython/pull/124773
gh-124872: Move PyThreadState to first argument for consistency #124774https://github.com/python/cpython/pull/124774
gh-124872: Replace enter/exit events with "switched" #124776https://github.com/python/cpython/pull/124776
Nexthttps://github.com/python/cpython/issues/119333?timeline_page=1
friedhttps://github.com/fried
type-featureA feature request or enhancementhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-feature%22
on May 21, 2024https://github.com/python/cpython/issues/119333#event-12883520484
mdboomhttps://github.com/mdboom
topic-C-APIhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22topic-C-API%22
on May 22, 2024https://github.com/python/cpython/issues/119333#event-12893209143
gvanrossumhttps://github.com/gvanrossum
on Sep 24, 2024https://github.com/python/cpython/issues/119333#event-14374097819
gh-119333: Add C api to have contextvar enter/exit callbacks (#119335)https://github.com/python/cpython/commit/d87482bc4ee9458d6ba16140e7bc008637dbbb16
gh-119333https://github.com/python/cpython/issues/119333
#119335https://github.com/python/cpython/pull/119335
d87482bhttps://github.com/python/cpython/commit/d87482bc4ee9458d6ba16140e7bc008637dbbb16
kumaraditya303https://github.com/kumaraditya303
on Sep 26, 2024https://github.com/python/cpython/issues/119333#event-14409874659
gh-119333: get interp from tstate for PyContext watchers(#124444)https://github.com/python/cpython/commit/46f5cbca4c37c57f718d3de0d7f7ddfc44298535
gh-119333https://github.com/python/cpython/issues/119333
#124444https://github.com/python/cpython/pull/124444
46f5cbchttps://github.com/python/cpython/commit/46f5cbca4c37c57f718d3de0d7f7ddfc44298535
kumaraditya303https://github.com/kumaraditya303
completedhttps://github.com/python/cpython/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Acompleted
on Sep 26, 2024https://github.com/python/cpython/issues/119333#event-14409945928
https://github.com/rhansen
rhansenhttps://github.com/rhansen
on Sep 27, 2024https://github.com/python/cpython/issues/119333#issuecomment-2380292271
@friedhttps://github.com/fried
#99633https://github.com/python/cpython/issues/99633
#99633 (comment)https://github.com/python/cpython/issues/99633#issuecomment-2377915344
rhansenhttps://github.com/rhansen
on Sep 28, 2024https://github.com/python/cpython/issues/119333#event-14442908071
pythongh-119333: Change PyContext_WatchCallback to take PyObjecthttps://github.com/rhansen/cpython/commit/84c233e5da0e833c3777bac276b6f7784f014cc3
pythongh-119333https://github.com/python/cpython/issues/119333
84c233ehttps://github.com/rhansen/cpython/commit/84c233e5da0e833c3777bac276b6f7784f014cc3
pythongh-119333: Change PyContext_WatchCallback to take PyObjecthttps://github.com/rhansen/cpython/commit/37dae27f22d4182b6e97a7149c114d03647c3991
pythongh-119333https://github.com/python/cpython/issues/119333
37dae27https://github.com/rhansen/cpython/commit/37dae27f22d4182b6e97a7149c114d03647c3991
pythongh-119333: Back up exception before calling PyContext_WatchCall…https://github.com/rhansen/cpython/commit/1636f1014fa16cc5fc23def724d861d679c98f59
pythongh-119333https://github.com/python/cpython/issues/119333
1636f10https://github.com/rhansen/cpython/commit/1636f1014fa16cc5fc23def724d861d679c98f59
pythongh-119333: Back up exception before calling PyContext_WatchCall…https://github.com/rhansen/cpython/commit/9e4ea98b2f45e035c47c52d7eb31f3afc8a84a0f
pythongh-119333https://github.com/python/cpython/issues/119333
9e4ea98https://github.com/rhansen/cpython/commit/9e4ea98b2f45e035c47c52d7eb31f3afc8a84a0f
pythongh-119333, pythongh-99633: Refine contextvars documentationhttps://github.com/rhansen/cpython/commit/c99ca89dc8d20d4f61627a4b06e1b4efd701e084
pythongh-119333https://github.com/python/cpython/issues/119333
pythongh-99633https://github.com/python/cpython/issues/99633
c99ca89https://github.com/rhansen/cpython/commit/c99ca89dc8d20d4f61627a4b06e1b4efd701e084
pythongh-119333, pythongh-99633: Refine contextvars documentationhttps://github.com/rhansen/cpython/commit/b16f493aecd5ba6ad3ad957f6acd9b5a14d8c860
pythongh-119333https://github.com/python/cpython/issues/119333
pythongh-99633https://github.com/python/cpython/issues/99633
b16f493https://github.com/rhansen/cpython/commit/b16f493aecd5ba6ad3ad957f6acd9b5a14d8c860
pythongh-119333: Move PyThreadState to first argument for consistencyhttps://github.com/rhansen/cpython/commit/efab225f3fc2f0d962d236b2e89df9d6628507ce
pythongh-119333https://github.com/python/cpython/issues/119333
efab225https://github.com/rhansen/cpython/commit/efab225f3fc2f0d962d236b2e89df9d6628507ce
pythongh-119333: Change PyContext_WatchCallback to take PyObjecthttps://github.com/rhansen/cpython/commit/c1a51a818bf947791def5954e8e61d76bb4434c7
pythongh-119333https://github.com/python/cpython/issues/119333
c1a51a8https://github.com/rhansen/cpython/commit/c1a51a818bf947791def5954e8e61d76bb4434c7
pythongh-119333: Change PyContext_WatchCallback return type to voidhttps://github.com/rhansen/cpython/commit/66fdcf5e82d27e3aea1e526fed5131d2a2151742
pythongh-119333https://github.com/python/cpython/issues/119333
66fdcf5https://github.com/rhansen/cpython/commit/66fdcf5e82d27e3aea1e526fed5131d2a2151742
rhansenhttps://github.com/rhansen
on Sep 30, 2024https://github.com/python/cpython/issues/119333#event-14447713295
pythongh-119333, pythongh-99633: Replace enter/exit events with "swit…https://github.com/rhansen/cpython/commit/b55f4cf65b711918a5d9641dc9236026e599830a
pythongh-119333https://github.com/python/cpython/issues/119333
pythongh-99633https://github.com/python/cpython/issues/99633
b55f4cfhttps://github.com/rhansen/cpython/commit/b55f4cf65b711918a5d9641dc9236026e599830a
fixup! pythongh-119333: Back up exception before calling PyContext_Wa…https://github.com/rhansen/cpython/commit/ffa8cc854dacb1a86f22f54e260437f5e84298a7
pythongh-119333https://github.com/python/cpython/issues/119333
ffa8cc8https://github.com/rhansen/cpython/commit/ffa8cc854dacb1a86f22f54e260437f5e84298a7
Merge branch 'pythongh-119333-exception' into HEADhttps://github.com/rhansen/cpython/commit/32fd02a8c91daa97e02ae2768b74ecd8694fdb8e
pythongh-119333https://github.com/python/cpython/issues/119333
32fd02ahttps://github.com/rhansen/cpython/commit/32fd02a8c91daa97e02ae2768b74ecd8694fdb8e
Merge branch 'pythongh-119333-99633-docs' into HEADhttps://github.com/rhansen/cpython/commit/f1b30e30f1ba0565545f082a0fb1484812fca559
pythongh-119333https://github.com/python/cpython/issues/119333
f1b30e3https://github.com/rhansen/cpython/commit/f1b30e30f1ba0565545f082a0fb1484812fca559
Merge branch 'pythongh-119333-notify' into HEADhttps://github.com/rhansen/cpython/commit/a8e24526efdc6a5a38d52338ba4d38a9f3597fba
pythongh-119333https://github.com/python/cpython/issues/119333
a8e2452https://github.com/rhansen/cpython/commit/a8e24526efdc6a5a38d52338ba4d38a9f3597fba
pythongh-119333, pythongh-99633: Replace enter/exit events with "swit…https://github.com/rhansen/cpython/commit/00396e03d2d999de77f79270a41c1280cc4f03ed
pythongh-119333https://github.com/python/cpython/issues/119333
pythongh-99633https://github.com/python/cpython/issues/99633
00396e0https://github.com/rhansen/cpython/commit/00396e03d2d999de77f79270a41c1280cc4f03ed
fixup! pythongh-119333: Back up exception before calling PyContext_Wa…https://github.com/rhansen/cpython/commit/212948c1e123f5de2f748c13c528e762b7257e07
pythongh-119333https://github.com/python/cpython/issues/119333
212948chttps://github.com/rhansen/cpython/commit/212948c1e123f5de2f748c13c528e762b7257e07
Merge branch 'pythongh-119333-exception' into HEADhttps://github.com/rhansen/cpython/commit/cea403fd84fe941f561ef9cba4f87681041360cd
pythongh-119333https://github.com/python/cpython/issues/119333
cea403fhttps://github.com/rhansen/cpython/commit/cea403fd84fe941f561ef9cba4f87681041360cd
Merge branch 'pythongh-119333-99633-docs' into HEADhttps://github.com/rhansen/cpython/commit/1bb5210408c1a586b8fb16f092ee05ae36c87841
pythongh-119333https://github.com/python/cpython/issues/119333
1bb5210https://github.com/rhansen/cpython/commit/1bb5210408c1a586b8fb16f092ee05ae36c87841
Merge branch 'pythongh-119333-notify' into HEADhttps://github.com/rhansen/cpython/commit/ebac5692034d1ace09cc791288979738863b8efd
pythongh-119333https://github.com/python/cpython/issues/119333
ebac569https://github.com/rhansen/cpython/commit/ebac5692034d1ace09cc791288979738863b8efd
pythongh-119333, pythongh-99633: Replace enter/exit events with "swit…https://github.com/rhansen/cpython/commit/0b18cf1cff4f0293b99cd09942397bea50f3785f
pythongh-119333https://github.com/python/cpython/issues/119333
pythongh-99633https://github.com/python/cpython/issues/99633
0b18cf1https://github.com/rhansen/cpython/commit/0b18cf1cff4f0293b99cd09942397bea50f3785f
pythongh-119333, pythongh-99633: Replace enter/exit events with "swit…https://github.com/rhansen/cpython/commit/8242dce86d3e1180633141032c622b4648c27116
pythongh-119333https://github.com/python/cpython/issues/119333
pythongh-99633https://github.com/python/cpython/issues/99633
8242dcehttps://github.com/rhansen/cpython/commit/8242dce86d3e1180633141032c622b4648c27116
Merge branch 'pythongh-119333-exception' into HEADhttps://github.com/rhansen/cpython/commit/1656f3c43080496202eaa23cd1111d0264b30bfc
pythongh-119333https://github.com/python/cpython/issues/119333
1656f3chttps://github.com/rhansen/cpython/commit/1656f3c43080496202eaa23cd1111d0264b30bfc
Merge branch 'pythongh-119333-99633-docs' into HEADhttps://github.com/rhansen/cpython/commit/2aff41a602efbc0bd5c7fa89aefba6dc88d12679
pythongh-119333https://github.com/python/cpython/issues/119333
2aff41ahttps://github.com/rhansen/cpython/commit/2aff41a602efbc0bd5c7fa89aefba6dc88d12679
Merge branch 'pythongh-119333-notify' into HEADhttps://github.com/rhansen/cpython/commit/029a0c99cec4c61da72d8850cf3490b7e4840657
pythongh-119333https://github.com/python/cpython/issues/119333
029a0c9https://github.com/rhansen/cpython/commit/029a0c99cec4c61da72d8850cf3490b7e4840657
Sign up for freehttps://github.com/signup?return_to=https://github.com/python/cpython/issues/119333
Sign in to commenthttps://github.com/login?return_to=https://github.com/python/cpython/issues/119333
topic-C-APIhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22topic-C-API%22
type-featureA feature request or enhancementhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-feature%22
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.