-
-
Notifications
You must be signed in to change notification settings - Fork 357
gh-3108: Avoid materializing f_locals for KI protection #3110
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 all commits
Commits
Show all changes
39 commits
Select commit
Hold shift + click to select a range
5d51c56
gh-3108: avoid materializing f_locals by using weakrefs to code objec…
graingert ea42ad0
enable ki protection on async_generator objects
graingert c755593
avoid adding an extra coroutine wrapper to Task coros
graingert 6bf63f2
fix returning the wrong object in (enable|disable)_ki_protection
graingert 65aa8f4
remove KIProtectionSignature from _check_type_completeness.json
graingert 748f876
fix refcycles
graingert fccf4ff
add newsfragment
graingert 56696a2
fix mypy
graingert a7272d8
now that the type annotation for enable_ki_protection is fixed, we ne…
graingert 3ea6617
pre-commit
graingert 0ed35a7
add test for ki protection leaking accross local functions
graingert ec30d7b
add fix for ki protection leaking accross local functions
graingert 6998a5c
do slots properly
graingert 1f0fc6f
python 3.8 support
graingert 480aa01
test reading currently_ki_protected doesn't freeze locals
graingert b7a1132
cover some tricky bits of ki.py
graingert 05b1fa1
cover a potentially impossible scenario
graingert f8dc61d
eek out some last coverage of the eeking out coverage tests
graingert 9e6bddb
even more partial coverage
graingert d5e539f
Update src/trio/_core/_ki.py
graingert 408d1ae
cleaner _IdRef.__eq__
graingert 5ba9bd8
if the current_task().coro.cr_frame is in the stack ki_protection_ena…
graingert 49bd5c3
Update newsfragments/3108.bugfix.rst
graingert 76b0c79
avoid copying code objects for ki protected function
graingert fa6cd8e
Update src/trio/_core/_ki.py
graingert be38f4c
Update src/trio/_core/_ki.py
graingert 8136a82
Merge branch 'main' of github.com:python-trio/trio into ki-with-code-…
graingert b21bde6
remove workaround for 3.8
graingert 0b2dd1a
Add docs and update news
graingert 12329c7
wrap ki protection locals demos in async def so they work
graingert 97a9eb2
add newsfragment for 2670
graingert 022bd3d
Apply suggestions from code review
graingert 4fe4d36
use peo614
graingert 0c80de3
add tests for passing on inspect flags
graingert 9bbaef0
Merge branch 'ki-with-code-objects' of github.com:graingert/trio into…
graingert 1e10e62
'return; yield' isn't considered covered
graingert 0cd1feb
Update newsfragments/3108.bugfix.rst
graingert 6e97f9a
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 5d76de2
Merge branch 'main' into ki-with-code-objects
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 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
:func:`inspect.iscoroutinefunction` and the like now give correct answers when | ||
called on KI-protected functions. | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
Rework KeyboardInterrupt protection to track code objects, rather than frames, | ||
as protected or not. The new implementation no longer needs to access | ||
``frame.f_locals`` dictionaries, so it won't artificially extend the lifetime of | ||
local variables. Since KeyboardInterrupt protection is now imposed statically | ||
(when a protected function is defined) rather than each time the function runs, | ||
its previously-noticeable performance overhead should now be near zero. | ||
The lack of a call-time wrapper has some other benefits as well: | ||
|
||
* :func:`inspect.iscoroutinefunction` and the like now give correct answers when | ||
called on KI-protected functions. | ||
|
||
* Calling a synchronous KI-protected function no longer pushes an additional stack | ||
frame, so tracebacks are clearer. | ||
|
||
* A synchronous KI-protected function invoked from C code (such as a weakref | ||
finalizer) is now guaranteed to start executing; previously there would be a brief | ||
window in which KeyboardInterrupt could be raised before the protection was | ||
established. | ||
|
||
One minor drawback of the new approach is that multiple instances of the same | ||
closure share a single KeyboardInterrupt protection state (because they share a | ||
single code object). That means that if you apply | ||
`@enable_ki_protection <trio.lowlevel.enable_ki_protection>` to some of them | ||
and not others, you won't get the protection semantics you asked for. See the | ||
documentation of `@enable_ki_protection <trio.lowlevel.enable_ki_protection>` | ||
for more details and a workaround. | ||
graingert marked this conversation as resolved.
Show resolved
Hide resolved
|
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
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
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.