-
-
Notifications
You must be signed in to change notification settings - Fork 33.2k
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
Changes from 14 commits
b8767c3
55e642a
1e0317a
0d54500
3592633
80d6f55
9ec2260
2b4bd53
1ed9657
546538a
a7b60d6
c7e5b85
3480c66
c210351
c80dd9d
4b78fd3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,6 +27,43 @@ PyAPI_FUNC(PyObject *) PyContext_CopyCurrent(void); | |
| PyAPI_FUNC(int) PyContext_Enter(PyObject *); | ||
| PyAPI_FUNC(int) PyContext_Exit(PyObject *); | ||
|
|
||
| #define Py_FOREACH_CONTEXT_EVENT(V) \ | ||
| V(ENTER) \ | ||
| V(EXIT) | ||
|
|
||
| typedef enum { | ||
| #define Py_DEF_EVENT(op) Py_CONTEXT_EVENT_##op, | ||
| Py_FOREACH_CONTEXT_EVENT(Py_DEF_EVENT) | ||
| #undef Py_DEF_EVENT | ||
| } PyContextEvent; | ||
|
|
||
| /* | ||
| * A Callback to clue in non-python contexts impls about a | ||
|
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. I don't understand this comment, what is meant by clue in? Also what is change in active python context? |
||
| * 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. | ||
|
|
||
|
|
||
| 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. |
Uh oh!
There was an error while loading. Please reload this page.