-
-
Notifications
You must be signed in to change notification settings - Fork 31.9k
gh-119333: Add c-api to have contextvar enter/exit callbacks #119335
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
b8767c3
Add c-api to have contextvar enter/exit callbacks
fried 55e642a
📜🤖 Added by blurb_it.
blurb-it[bot] 1e0317a
fix exception codes for 3.13+
fried 0d54500
fix docs
fried 3592633
remove weird line endings from the blurbit tool
fried 80d6f55
fix unraisable error handling in test_capi
fried 9ec2260
fix typos and naming for pep7
fried 2b4bd53
Add ignores to c-analyzer
fried 1ed9657
Update Doc/c-api/contextvars.rst for pep-7
fried 546538a
Update Python/context.c - pep7
fried a7b60d6
Move macro to internal
fried c7e5b85
Fix the rest of pep-7 issues
fried 3480c66
Fix Foreach Macro Name
fried c210351
Yeah can't internalize foreach macro
fried c80dd9d
de-macro-ing as suggested by guido
fried 4b78fd3
default switch case ?
fried File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,6 +27,38 @@ PyAPI_FUNC(PyObject *) PyContext_CopyCurrent(void); | |
PyAPI_FUNC(int) PyContext_Enter(PyObject *); | ||
PyAPI_FUNC(int) PyContext_Exit(PyObject *); | ||
|
||
typedef enum { | ||
Py_CONTEXT_EVENT_ENTER, | ||
Py_CONTEXT_EVENT_EXIT, | ||
} PyContextEvent; | ||
|
||
/* | ||
* A Callback to clue in non-python contexts impls about a | ||
* change in the active python context. | ||
* | ||
* The callback is invoked with the event and a reference to = | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove the |
||
* the context after its entered and before its exited. | ||
* | ||
* if the callback returns with an exception set, it must return -1. Otherwise | ||
* it should return 0 | ||
*/ | ||
typedef int (*PyContext_WatchCallback)(PyContextEvent, PyContext *); | ||
|
||
/* | ||
* Register a per-interpreter callback that will be invoked for context object | ||
* enter/exit events. | ||
* | ||
* Returns a handle that may be passed to PyContext_ClearWatcher on success, | ||
* or -1 and sets and error if no more handles are available. | ||
*/ | ||
PyAPI_FUNC(int) PyContext_AddWatcher(PyContext_WatchCallback callback); | ||
|
||
/* | ||
* Clear the watcher associated with the watcher_id handle. | ||
* | ||
* Returns 0 on success or -1 if no watcher exists for the provided id. | ||
*/ | ||
PyAPI_FUNC(int) PyContext_ClearWatcher(int watcher_id); | ||
|
||
/* Create a new context variable. | ||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
Misc/NEWS.d/next/C API/2024-05-21-18-28-44.gh-issue-119333.OTsYVX.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Add :c:func:`PyContext_AddWatcher` and :c:func:`PyContext_ClearWatcher` APIs to | ||
register callbacks to receive notification on enter and exit of context objects. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand this comment, what is meant by clue in? Also what is change in active python context?