Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-79932: raise exception if frame.clear() is called on a suspended frame#111792

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
iritkatriel merged 7 commits intopython:mainfromiritkatriel:suspended_clear
Nov 7, 2023

Conversation

iritkatriel
Copy link
Member

@iritkatrieliritkatriel commentedNov 6, 2023
edited by github-actionsbot
Loading

Copy link
Member

@gvanrossumgvanrossum left a comment

Choose a reason for hiding this comment

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

There is already a perfectly general mechanism to turn selected warnings into exceptions, using the warnings module and/or the -W flag. Why do we need a specific flag argument here to accomplish the same thing?

@iritkatriel
Copy link
MemberAuthor

I need to turn it into an exception in a particular call (always). -W wouldn't work for that. Maybe I can use the warnings module locally though?

@gvanrossum
Copy link
Member

What’s the use case for this need? Testing? Or something else?

@iritkatriel
Copy link
MemberAuthor

The reported bug was about traceback.clear_frames, which is called from unittest and can cause the program to freeze.

@iritkatriel
Copy link
MemberAuthor

Another option is to expose the frame state to python, so that the caller can avoid calling clear on a suspended frame.

@gvanrossum
Copy link
Member

Another option is to expose the frame state to python, so that the caller can avoid calling clear on a suspended frame.

Yeah, given that we have an API here to manipulate the frame, and a reason for not using that API when the frame is suspended, it makes sense to allow the caller to detect the frame is in that state. At least that feels better than having a custom flag to turn the warning into an error.

But: I'm not sure this requires deprecation even. It's just a bug, right?frame_clear() looks like it is intended to clear the locals only after the frame has exited -- if it's still running, we don't want to interfere with it. But a suspended frame, in this context, should be seen as not having exited. The actual state check is just wrong, it incorrectly categorizes "suspended" together with "exited" instead of "running". Since the function is already expected to raiseRuntimeError, I don't see why we need to tread so lightly around fixing this (to me) obvious bug.

@iritkatriel
Copy link
MemberAuthor

That was my initial plan, buta couple of test failed. I can just change the tests.

@iritkatrieliritkatriel changed the titlegh-79932: deprecate clearing a suspended frame and add option to get exception. Apply in traceback.clear_frames().gh-79932: raise exception if frame.clear() is called on a suspended frameNov 6, 2023
@gvanrossum
Copy link
Member

That was my initial plan, buta couple of test failed. I can just change the tests.

Most likely those tests were mindlessly testing that the code did what it did, rather than what it should do.

Copy link
Member

@gvanrossumgvanrossum left a comment

Choose a reason for hiding this comment

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

Thanks, now it makes sense to me.

@gvanrossum
Copy link
Member

Is it worth backporting?

@iritkatriel
Copy link
MemberAuthor

I think there are situations where you clear a suspended frame, it closes the generator, and there's no problem because you don't try to use it anymore. Backporting this could break that.

@gvanrossum
Copy link
Member

Is that really a feature? Then we need to change what we did here?

@iritkatriel
Copy link
MemberAuthor

I wouldn't go as far as calling it a feature. It's possible that sometimes this bug is not causing an actual problem, and it will if we raise exceptions.

@gvanrossum
Copy link
Member

Okay, that's fair. So in 3.13 it will raise, but in 3.12 it might work, or it might cause a deadlock like in the original report. And we recommend that the OP fix their code to stop doing this.

hugovk pushed a commit to hugovk/cpython that referenced this pull requestNov 8, 2023
aisk pushed a commit to aisk/cpython that referenced this pull requestFeb 11, 2024
Glyphack pushed a commit to Glyphack/cpython that referenced this pull requestSep 2, 2024
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@gvanrossumgvanrossumgvanrossum approved these changes

@markshannonmarkshannonAwaiting requested review from markshannonmarkshannon is a code owner

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

traceback.clear_frames manages to deadlock a background task
2 participants
@iritkatriel@gvanrossum

[8]ページ先頭

©2009-2025 Movatter.jp