-
-
Notifications
You must be signed in to change notification settings - Fork 32.1k
bpo-43760: Document PyThreadState.use_tracing removal #28527
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 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
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.
This may be dangerous,
state->cframe
is a stack-allocated structure so I am not sure if is valid in all accesses oftstate->cframe
and has the same semantics. Maybe @markshannon can clarifyThere 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.
Cython and greenlet now uses
tstate->cframe->use_tracing
. Do you mean that it's a bug?Uh oh!
There was an error while loading. Please reload this page.
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.
It may be. That is only valid as long as the executing frame is alive. For instance a for generators that may segfaultActually, I am wrong, if
tstate->cframe->use_tracing
is notNULL
then it must be valid.The other question here is that
tstate->cframe->use_tracing
is still private, so I don't like recommending using it because it can change yet again.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.
This may be dangerous for two reasons:
tstate->use_tracing
had global effect before, whiletstate->cframe->use_tracing
only affects the last executing frame. Modifiying this value only affects that particular frame. The semantics are different.tstate->cframe
points to a stack allocated variable in ceval. Accessing this from heap objects may be dangerous.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.
Hum. I will design an API to abstract access to use_tracing. For now, I update my PR for the bare minimum: only document that the member is removed.
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.
Reading from, or writing to,
tstate->cframe->use_tracing
is OK, what is dangerous is hanging on to a pointer totstate->cframe
.use_tracing
must always be accessed throughtstate
(and with the GIL held).However, it may change in the future, we should make it clear that this advice only applies to 3.10.
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.
There is also change in semantics, no? before
tstate->use_tracing
had global effect but this only affects the current frame.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 may be wrong, but AFAIR, it was used as a flag to disable tracing in the current frame. That would also motivate why it was moved out of the thread state now.
Uh oh!
There was an error while loading. Please reload this page.
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.
Right, but it would have effect on the whole call stack. Imagine you set it to false, then all callers would stopped tracing when they get to run again after the callee returns. iIUC now that won't happen because you are only modifying the one in the frame running and all its callees
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.
Could setting the tracefunc to NULL be the alternative? There are some differences in 3.9 between setting use_trace to False and tracefunc to NULL, but I suspect the latter can be used. Keep in mind that this is implementation & version specific functionality so it's probably ok not to support all cases that 3.9 did.