GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — bpo-39947: Add PyThreadState_SetTrace() function by vstinner · Pull Request #29121 · python/cpython

Conversation

@vstinner

@vstinner vstinner commented Oct 21, 2021 •
edited by bedevere-bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

Add new PyThreadState_SetProfile() and PyThreadState_SetTrace()
functions to set the profile and the trace function of a Python
thread state.

  • Rename _PyEval_SetProfile() to PyThreadState_SetProfile().
  • Rename _PyEval_SetTrace() to PyThreadState_SetTrace().
  • Rename is_tstate_valid() to _PyThreadState_CheckConsistency().

https://bugs.python.org/issue39947

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@vstinner
bpo-39947: Add PyThreadState_SetTrace() function
ec8b6b6
Add new PyThreadState_SetProfile() and PyThreadState_SetTrace()
functions to set the profile and the trace function of a Python
thread state.

* Rename _PyEval_SetProfile() to PyThreadState_SetProfile().
* Rename _PyEval_SetTrace() to PyThreadState_SetTrace().
* Rename is_tstate_valid() to _PyThreadState_CheckConsistency().
@vstinner
vstinner requested a review from markshannon as a code owner October 21, 2021 13:20
@bedevere-bot bedevere-bot added the awaiting core review label Oct 21, 2021
@the-knights-who-say-ni the-knights-who-say-ni added the CLA signed label Oct 21, 2021
@vstinner

vstinner commented Oct 21, 2021

Copy link
Copy Markdown
Member Author

PyThreadState_SetProfile() is needed by the Python yappi profiler:

ts->c_profilefunc = _yapp_callback;

Source: https://github.com/sumerc/yappi/blob/8bf7a650066f104f59c3cae4a189ec15e7d51c8c/yappi/_yappi.c#L1258

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@vstinner

vstinner commented Oct 21, 2021

Copy link
Copy Markdown
Member Author

See also discussion at: https://bugs.python.org/issue43760

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@vstinner

vstinner commented Oct 21, 2021

Copy link
Copy Markdown
Member Author

cc @markshannon

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@vstinner

vstinner commented Oct 21, 2021

Copy link
Copy Markdown
Member Author

I don't understand well the relationship between PyThreadState.c_tracefunc and PyFrameObject.f_trace. Currently, sys.settrace() function suggests setting frame.f_trace = tracefunc directly in Python: https://docs.python.org/dev/library/sys.html#sys.settrace

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@vstinner

vstinner commented Oct 22, 2021

Copy link
Copy Markdown
Member Author

PyThreadState_SetProfile() is needed by the Python yappi profiler:

I'm not sure if yappi can use it directly, since PyThreadState_SetProfile() requires to hold the GIL. But it's more a yappi issue, than an API issue IMO.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions

github-actions Bot commented Nov 22, 2021

Copy link
Copy Markdown

This PR is stale because it has been open for 30 days with no activity.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions github-actions Bot added the stale Stale PR or inactive for long period of time. label Nov 22, 2021
JimJJewett
JimJJewett reviewed Feb 2, 2022
View reviewed changes

@JimJJewett JimJJewett left a comment •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

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 think it would be helpful to add a 3rd column stating which of the trace/profile functions see each event type. In case this isn't pointing to the right place, Doc/c-api/init.rst 1556 or 1616 depending on before/after

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
JimJJewett
JimJJewett reviewed Feb 2, 2022
View reviewed changes
Comment thread Misc/NEWS.d/next/C API/2021-10-21-15-00-43.bpo-39947.KOqrdL.rst
@@ -0,0 +1,3 @@
Add new :c:func:`PyThreadState_SetProfile` and
:c:func:`PyThreadState_SetTrace` functions to set the profile and the trace

@JimJJewett JimJJewett Feb 2, 2022

Copy link
Copy Markdown

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 would add "(replacing _PyEval_SetProfile)" and "(replacing _PyEval_SetTrace)" since those are likely to be the names people have if they are searching for changes, instead of just reading in advance.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@JimJJewett JimJJewett Feb 2, 2022

Copy link
Copy Markdown

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.

Also mention renaming and move is_tstate_valid to _PyThreadState_CheckConsistency

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@vstinner vstinner Feb 3, 2022

Copy link
Copy Markdown
Member Author

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.

is_tstate_valid() is a static function, it cannot be used outside ceval.c. We don't document changes which don't affected the public C API.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@vstinner vstinner Feb 3, 2022

Copy link
Copy Markdown
Member Author

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 would add "(replacing _PyEval_SetProfile)" and "(replacing _PyEval_SetTrace)" since those are likely to be the names people have if they are searching for changes, instead of just reading in advance.

Usually, we never mention private functions in the changelog.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@vstinner

vstinner commented Feb 3, 2022

Copy link
Copy Markdown
Member Author

I think it would be helpful to add a 3rd column stating which of the trace/profile functions see each event type. In case this isn't pointing to the right place, Doc/c-api/init.rst 1556 or 1616 depending on before/after

If you consider that the doc should be completed, please open a new issue. I don't see a direct relationship between your comment and my PR adding new functions.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@vstinner vstinner closed this Feb 23, 2022
@vstinner
vstinner deleted the pyframe_gettrace branch February 23, 2022 23:29
@vstinner

vstinner commented Feb 23, 2022

Copy link
Copy Markdown
Member Author

I'm not convinced that there are 3rd party Python projects which need and will use this function. I prefer to close this PR for now. I may revisit it later, if more users of this function are discovered.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

This was referenced Sep 15, 2022
The DISPATCH() macro is not as efficient as it could be (move PyThreadState.use_tracing) #87926
Closed
[C API] Prepare the C API to make PyThreadState opaque: add getter functions #84128
Closed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@markshannon markshannon Awaiting requested review from markshannon markshannon is a code owner
1 more reviewer
@JimJJewett JimJJewett JimJJewett left review comments
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

awaiting core review stale Stale PR or inactive for long period of time.

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

4 participants

@vstinner @JimJJewett @the-knights-who-say-ni @bedevere-bot
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.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.