FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-119333: Add c-api to have contextvar enter/exit callbacks by fried · Pull Request #119335 · python/cpython · GitHub

Repository navigation

gh-119333: Add c-api to have contextvar enter/exit callbacks - #119335

Merged
gvanrossum merged 16 commits into
python:mainfrom
fried:pull-request-context-watchers
Sep 24, 2024
Merged

gvanrossum merged 16 commits into
python:mainfrom
fried:pull-request-context-watchers

Conversation

fried commented May 21, 2024 •
edited by github-actions Bot
Loading

Copy link
Copy Markdown
Contributor

This PR implements gh-119333, allowing for setting a callback function on PyContext_Enter and PyContext_Exit from the c-api

Co-authored-by: @itamaro


📚 Documentation preview 📚: https://cpython-previews--119335.org.readthedocs.build/

Comment thread Python/context.c

1st1 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I'm OK with this change. The motivation for adding it seems reasonable. I'll let @ericsnowcurrently review it properly, but I skimmed through the code and I like the approach.

erlend-aasland left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Some minor remarks after a quick look: please align the naming with PEP-7 and use Py (not PY) prefixes for the macros.

Comment thread Doc/c-api/contextvars.rst Outdated

fried commented May 22, 2024

Copy link
Copy Markdown
Contributor Author

@ericsnowcurrently Am I doing this wrong, Having an issue with Check if generated files are up to date I followed the example for the other watcher checks and they use the same style globals. Also I can't run the check locally it on my mac it doesn't seem to like clang.

Comment thread Doc/c-api/contextvars.rst Outdated
Comment thread Doc/c-api/contextvars.rst Outdated
Comment thread Python/context.c Outdated
Comment thread Python/context.c Outdated
Comment thread Python/context.c Outdated
Comment thread Include/cpython/context.h Outdated
Comment thread Include/cpython/context.h Outdated

Copy link
Copy Markdown
Member

Am I doing this wrong, Having an issue with Check if generated files are up to date I followed the example for the other watcher checks and they use the same style globals.

Try copying similar entries in Tools/c-analyzer/cpython/ignored.tsv and then editing them to match the new variables.

Also I can't run the check locally it on my mac it doesn't seem to like clang.

Yeah, sorry, this is definitely a gap.

fried force-pushed the pull-request-context-watchers branch from e2fef0c to c210351 Compare September 23, 2024 20:01
Comment thread Python/context.c
gvanrossum merged commit d87482b into python:main Sep 24, 2024
Comment thread Python/context.c
static void notify_context_watchers(PyContextEvent event, PyContext *ctx)
{
assert(Py_REFCNT(ctx) > 0);
PyInterpreterState *interp = _PyInterpreterState_GET();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

FWIW you can get interp from tstate which is already known, it would have avoided one more tls read which is slow on msvc.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Sorry. We’ll fix it tomorrow. Any other concerns?

Comment thread Include/cpython/context.h
} PyContextEvent;

/*
* A Callback to clue in non-python contexts impls about a

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I don't understand this comment, what is meant by clue in? Also what is change in active python context?

Comment thread Include/cpython/context.h
* 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 =

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Remove the =, it adds no useful info and is confusing.

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants


Back | FazBrowse Home | New Git URL