-
-
Notifications
You must be signed in to change notification settings - Fork 347
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
don't use f_locals for foreign async generators #3112
Merged
graingert
merged 20 commits into
python-trio:main
from
graingert:dont-use-f_locals-for-agen-finalization
Nov 21, 2024
Merged
Changes from 15 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
be11787
add test for gc in foreign async generators
graingert 0ec9f8a
use a strong set of ids for foriegn async gens
graingert 1504187
Update src/trio/_core/_asyncgens.py
graingert 64ce3c4
add newsfragment
graingert f435d35
Update newsfragments/3112.bugfix.rst
graingert b3cdced
move name_asyncgen later than self.foreign.remove
graingert 1eae0c5
remove 3.6 compat code
graingert a3c1816
move sniffio import to top
graingert fc1f5bb
asyncio.run introduced some breakage
graingert c4010fc
Merge branch 'main' of github.com:python-trio/trio into dont-use-f_lo…
graingert 0ebad56
Merge branch 'main' into dont-use-f_locals-for-agen-finalization
graingert 28957e0
ki protect asyncgen finalizers, because it's critical to run
graingert 9f1823a
try asyncio.run again
graingert d2f9c3c
Revert "try asyncio.run again"
graingert b21e6ef
well that just got worse
graingert 4807c3b
Merge branch 'main' of github.com:python-trio/trio into dont-use-f_lo…
graingert 2befccc
be surgicial in KI-unprotection
graingert 933b1c3
make f positional only
graingert 8fdaaf5
restore comment
graingert ca6e01c
Merge branch 'main' into dont-use-f_locals-for-agen-finalization
graingert 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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
Rework foreign async generator finalization to track async generator | ||
ids rather than mutating ``ag_frame.f_locals``. This fixes an issue | ||
with the previous implementation: locals' lifetimes will no longer be | ||
extended by materialization in the ``ag_frame.f_locals`` dictionary that | ||
the previous finalization dispatcher logic needed to access to do its work. |
This file contains 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
This file contains 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
Oops, something went wrong.
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.
actually what do we want to happen here if there's a KI? We want long running finalizers to be interruptible, but then the KeyboardInterrupt exception just gets lost so you need to hit Ctrl+C again to terminate trio
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.
Where does the KI get lost?
If it's in this
closer
after we call.send(None)
, doesn't it get raised here and will propagate up? I assume propagation here is fine because we already have aRuntimeError
being raised here.(I'm basing my assumptions off how generators behave, I don't know anything about async generator cleanup...)
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.
The finalizer gets called by tp_finalize which is called by the GC which catches the exception
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 see... could we catch the
KeyboardInterrupt
and basically tell trio that it got another Ctrl+C? It seems to be raised normally:(I also got this great error message in the REPL while playing around with this...)
Funny error message I ran into in the REPL
Not the most clear :^)
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.
But the message says the exception is ignored?
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.
Maybe we could call
signal.raise_signal(signal.SIGINT)
in theexcept KeyboardInterrupt:
and call it a day? Not a great solution IMO. (though actually that ... would probably raise in that except statement. ouch? nevermind)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.
Hmm. The except KeyboardInterrupt would have to be outside the _finalize_without_ki_protection
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.
How about this awful hack?:
edit: sorry, your comments weren't showing.
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 what I'm going to do here is put the KI protection on all the critical and guaranteed fast trio code and unprotect any of the host loop stuff. Then we can survey someone who uses guest mode and KI and async generators without aclose and find out what they want
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.
Another KI could arrive while constructing or decorating or load_fast-ing the killer function