René's URL Explorer Experiment


Title: Pass opaque state to PyContext_AddWatcher callback · Issue #127124 · python/cpython · GitHub

Open Graph Title: Pass opaque state to PyContext_AddWatcher callback · Issue #127124 · python/cpython

X Title: Pass opaque state to PyContext_AddWatcher callback · Issue #127124 · python/cpython

Description: Feature or enhancement Proposal: I would like to change the Context watcher C API (new to v3.14, see #119333) to pass an opaque pointer to the callback. Specifically, change: cpython/Include/cpython/context.h Lines 39 to 55 in e8bb053 /*...

Open Graph Description: Feature or enhancement Proposal: I would like to change the Context watcher C API (new to v3.14, see #119333) to pass an opaque pointer to the callback. Specifically, change: cpython/Include/cpytho...

X Description: Feature or enhancement Proposal: I would like to change the Context watcher C API (new to v3.14, see #119333) to pass an opaque pointer to the callback. Specifically, change: cpython/Include/cpytho...

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

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Pass opaque state to PyContext_AddWatcher callback","articleBody":"# Feature or enhancement\r\n\r\n### Proposal:\r\n\r\nI would like to change the [Context watcher C API](https://github.com/python/cpython/blob/e8bb05394164e7735f7a9de80a046953606a38eb/Include/cpython/context.h#L30-L62) (new to v3.14, see #119333) to pass an opaque pointer to the callback.  Specifically, change:\r\n\r\nhttps://github.com/python/cpython/blob/e8bb05394164e7735f7a9de80a046953606a38eb/Include/cpython/context.h#L39-L55\r\n\r\nto:\r\n\r\n```c\r\n/*\r\n * Context object watcher callback function.  arg is the same pointer passed to\r\n * PyContext_AddWatcher when the callback was registered.  The object passed to\r\n * the callback is event-specific; see PyContextEvent for details.\r\n *\r\n * if the callback returns with an exception set, it must return -1. Otherwise\r\n * it should return 0\r\n */\r\ntypedef int PyContext_WatchCallback(\r\n    void *arg, PyContextEvent event, PyObject *obj);\r\n\r\n/*\r\n * Register a per-interpreter callback that will be invoked for context events.\r\n * arg is an optional opaque pointer that is passed back to the callback; it\r\n * can be used to manage state if desired.\r\n *\r\n * Returns a handle that may be passed to PyContext_ClearWatcher on success,\r\n * or -1 and sets and error if no more handles are available.\r\n */\r\nPyAPI_FUNC(int) PyContext_AddWatcher(\r\n    PyContext_WatchCallback *callback, void *arg);\r\n```\r\n\r\nThe [original idea](https://discuss.python.org/t/v3-14a1-design-limitations-of-pycontext-addwatcher/68177/2) was for the callback to get any required state from the current context, but:\r\n\r\n  * The config/state is not guaranteed to be available in the context. For example, the Python code can do `ctx = contextvars.Context()` instead of `ctx = contextvars.copy_context()`. Or it can do `copy_context()`, but early during initialization and squirrel the context away for later use. The latter seems plausible for 3rd party libraries (where the user might not have much control).\r\n  * The same watcher callback cannot be registered multiple times simultaneously, each with its own config/state. This came up while I was refactoring [`TestContextObjectWatchers`](https://github.com/python/cpython/blob/e8bb05394164e7735f7a9de80a046953606a38eb/Lib/test/test_capi/test_watchers.py#L590) to add some more tests for a change I’m working on.\r\n\r\nI’m not sure how likely either is to come up in normal use, but I think it is worth changing the design before the 3.14 release cements it.\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/v3-14a1-design-limitations-of-pycontext-addwatcher/68177/4\r\n\r\ncc @fried\n\n\u003c!-- gh-linked-prs -->\n### Linked PRs\n* gh-127140\n* gh-127247\n\u003c!-- /gh-linked-prs -->\n","author":{"url":"https://github.com/rhansen","@type":"Person","name":"rhansen"},"datePublished":"2024-11-22T00:51:25Z","url":"https://github.com/python/cpython/issues/127124"}

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:f289d602-1168-9800-8d08-65cd5ed62536
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idCF2E:3CBB3E:368EA35:458E3A9:6B0231AE
html-safe-nonce4ab06de7fe8506be881edbd9ca8cb2215aa24f162045ac026a05d2ccdcda8d82
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDRjJFOjNDQkIzRTozNjhFQTM1OjQ1OEUzQTk6NkIwMjMxQUUiLCJ2aXNpdG9yX2lkIjoiMjU0NzI5NjIzMjYyMDA0NDcxOCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmacc3f0b29e8792394b5f89b08da6f2b3d89a577d936f53d80dc5a3e5252d3a48d0
hovercard-subject-tagissue:2681439294
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/127124/issue_layout
twitter:imagehttps://opengraph.githubassets.com/f565697bfb5280bdb55605c44859fa9a4e9adaadbbd41736e59b7a3ac54b5252/python/cpython/issues/127124
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/f565697bfb5280bdb55605c44859fa9a4e9adaadbbd41736e59b7a3ac54b5252/python/cpython/issues/127124
og:image:altFeature or enhancement Proposal: I would like to change the Context watcher C API (new to v3.14, see #119333) to pass an opaque pointer to the callback. Specifically, change: cpython/Include/cpytho...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamerhansen
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/127124#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fissues%2F127124
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%2F127124
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/127124
Reloadhttps://github.com/python/cpython/issues/127124
Reloadhttps://github.com/python/cpython/issues/127124
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/127124
New issuehttps://github.com/login?return_to=https://github.com/python/cpython/issues/127124
Pass opaque state to PyContext_AddWatcher callbackhttps://github.com/python/cpython/issues/127124#top
interpreter-core(Objects, Python, Grammar, and Parser dirs)https://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22interpreter-core%22
type-featureA feature request or enhancementhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-feature%22
https://github.com/rhansen
rhansenhttps://github.com/rhansen
on Nov 22, 2024https://github.com/python/cpython/issues/127124#issue-2681439294
Context watcher C APIhttps://github.com/python/cpython/blob/e8bb05394164e7735f7a9de80a046953606a38eb/Include/cpython/context.h#L30-L62
#119333https://github.com/python/cpython/issues/119333
cpython/Include/cpython/context.hhttps://github.com/python/cpython/blob/e8bb05394164e7735f7a9de80a046953606a38eb/Include/cpython/context.h#L39-L55
e8bb053https://github.com/python/cpython/commit/e8bb05394164e7735f7a9de80a046953606a38eb
original ideahttps://discuss.python.org/t/v3-14a1-design-limitations-of-pycontext-addwatcher/68177/2
TestContextObjectWatchershttps://github.com/python/cpython/blob/e8bb05394164e7735f7a9de80a046953606a38eb/Lib/test/test_capi/test_watchers.py#L590
https://discuss.python.org/t/v3-14a1-design-limitations-of-pycontext-addwatcher/68177/4https://discuss.python.org/t/v3-14a1-design-limitations-of-pycontext-addwatcher/68177/4
@friedhttps://github.com/fried
gh-127124: Pass optional state to context watcher callback #127140https://github.com/python/cpython/pull/127140
gh-127124: Change context watcher callback to a callable object #127247https://github.com/python/cpython/pull/127247
rhansenhttps://github.com/rhansen
type-featureA feature request or enhancementhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-feature%22
on Nov 22, 2024https://github.com/python/cpython/issues/127124#event-15390688680
rhansenhttps://github.com/rhansen
on Nov 22, 2024https://github.com/python/cpython/issues/127124#event-15393632932
pythongh-127124: Add opaque pointer to context watcher callbackhttps://github.com/rhansen/cpython/commit/2519a774188b8d3eb75a795a954719985092bc09
pythongh-127124https://github.com/python/cpython/issues/127124
2519a77https://github.com/rhansen/cpython/commit/2519a774188b8d3eb75a795a954719985092bc09
https://github.com/ZeroIntensity
ZeroIntensityhttps://github.com/ZeroIntensity
on Nov 22, 2024https://github.com/python/cpython/issues/127124#issuecomment-2493611007
rhansenhttps://github.com/rhansen
on Nov 22, 2024https://github.com/python/cpython/issues/127124#event-15405309107
fixup! pythongh-127124: Add opaque pointer to context watcher callbackhttps://github.com/rhansen/cpython/commit/f6ffc288d38c226c4c0656a55313969f83aa6270
pythongh-127124https://github.com/python/cpython/issues/127124
f6ffc28https://github.com/rhansen/cpython/commit/f6ffc288d38c226c4c0656a55313969f83aa6270
picnixzhttps://github.com/picnixz
interpreter-core(Objects, Python, Grammar, and Parser dirs)https://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22interpreter-core%22
on Nov 23, 2024https://github.com/python/cpython/issues/127124#event-15408226016
https://github.com/rhansen
rhansenhttps://github.com/rhansen
on Nov 24, 2024https://github.com/python/cpython/issues/127124#issuecomment-2495724557
https://github.com/ZeroIntensity
ZeroIntensityhttps://github.com/ZeroIntensity
on Nov 24, 2024https://github.com/python/cpython/issues/127124#issuecomment-2495725493
rhansenhttps://github.com/rhansen
on Nov 24, 2024https://github.com/python/cpython/issues/127124#event-15410047058
pythongh-127124: Pass optional state to context watcher callbackhttps://github.com/rhansen/cpython/commit/3130a2f894cef873069ea30f2a974ccbf9d363e4
pythongh-127124https://github.com/python/cpython/issues/127124
3130a2fhttps://github.com/rhansen/cpython/commit/3130a2f894cef873069ea30f2a974ccbf9d363e4
pythongh-127124: Pass optional state to context watcher callbackhttps://github.com/rhansen/cpython/commit/c9e95d40c9c15194b04b098e846fe2b9eae922ea
pythongh-127124https://github.com/python/cpython/issues/127124
c9e95d4https://github.com/rhansen/cpython/commit/c9e95d40c9c15194b04b098e846fe2b9eae922ea
pythongh-127124: Change context watcher callback to a callable objecthttps://github.com/rhansen/cpython/commit/e4367cbc5e71aa4d6e3634abe2164e7454b361f0
pythongh-127124https://github.com/python/cpython/issues/127124
e4367cbhttps://github.com/rhansen/cpython/commit/e4367cbc5e71aa4d6e3634abe2164e7454b361f0
fixup! pythongh-127124: Pass optional state to context watcher callbackhttps://github.com/rhansen/cpython/commit/133e00c08d488b297eb30f9833b2569cb08cd2d3
pythongh-127124https://github.com/python/cpython/issues/127124
133e00chttps://github.com/rhansen/cpython/commit/133e00c08d488b297eb30f9833b2569cb08cd2d3
fixup! pythongh-127124: Change context watcher callback to a callable…https://github.com/rhansen/cpython/commit/841e683900f6c80ebe951398e7b6b994b059ccd3
pythongh-127124https://github.com/python/cpython/issues/127124
841e683https://github.com/rhansen/cpython/commit/841e683900f6c80ebe951398e7b6b994b059ccd3
fixup! pythongh-127124: Change context watcher callback to a callable…https://github.com/rhansen/cpython/commit/3e28b5fa6af7add4676339119612fceba0598741
pythongh-127124https://github.com/python/cpython/issues/127124
3e28b5fhttps://github.com/rhansen/cpython/commit/3e28b5fa6af7add4676339119612fceba0598741
Sign up for freehttps://github.com/signup?return_to=https://github.com/python/cpython/issues/127124
Sign in to commenthttps://github.com/login?return_to=https://github.com/python/cpython/issues/127124
interpreter-core(Objects, Python, Grammar, and Parser dirs)https://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22interpreter-core%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.