Skip to content

bpo-39947: Add PyThreadState_SetTrace() function #29121

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

Closed
wants to merge 1 commit into from
Closed

bpo-39947: Add PyThreadState_SetTrace() function #29121

wants to merge 1 commit into from

Conversation

vstinner
Copy link
Member

@vstinner vstinner commented Oct 21, 2021

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

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
Copy link
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

@vstinner
Copy link
Member Author

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

@vstinner
Copy link
Member Author

cc @markshannon

@vstinner
Copy link
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

@vstinner
Copy link
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.

@github-actions
Copy link

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

@github-actions github-actions bot added the stale Stale PR or inactive for long period of time. label Nov 22, 2021
Copy link

@JimJJewett JimJJewett left a 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

@@ -0,0 +1,3 @@
Add new :c:func:`PyThreadState_SetProfile` and
:c:func:`PyThreadState_SetTrace` functions to set the profile and the trace

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.

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

Copy link
Member Author

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.

Copy link
Member Author

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.

@vstinner
Copy link
Member Author

vstinner commented Feb 3, 2022

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.

@vstinner vstinner closed this Feb 23, 2022
@vstinner vstinner deleted the pyframe_gettrace branch February 23, 2022 23:29
@vstinner
Copy link
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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting core review stale Stale PR or inactive for long period of time.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants