-
-
Notifications
You must be signed in to change notification settings - Fork 341
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* gh-3108: avoid materializing f_locals by using weakrefs to code objects instead * enable ki protection on async_generator objects * avoid adding an extra coroutine wrapper to Task coros * fix returning the wrong object in (enable|disable)_ki_protection * remove KIProtectionSignature from _check_type_completeness.json * fix refcycles * add newsfragment * fix mypy * now that the type annotation for enable_ki_protection is fixed, we need to fix the use of Any * pre-commit * add test for ki protection leaking accross local functions * add fix for ki protection leaking accross local functions * do slots properly * python 3.8 support * test reading currently_ki_protected doesn't freeze locals * cover some tricky bits of ki.py * cover a potentially impossible scenario * eek out some last coverage of the eeking out coverage tests * even more partial coverage * Update src/trio/_core/_ki.py * cleaner _IdRef.__eq__ * if the current_task().coro.cr_frame is in the stack ki_protection_enabled is current_task()._ki_protected * Update newsfragments/3108.bugfix.rst * avoid copying code objects for ki protected function * Update src/trio/_core/_ki.py * Update src/trio/_core/_ki.py Co-authored-by: EXPLOSION <[email protected]> * remove workaround for 3.8 * Add docs and update news Co-Authored-By: oremanj <[email protected]> * wrap ki protection locals demos in async def so they work * add newsfragment for 2670 * Apply suggestions from code review * use peo614 * add tests for passing on inspect flags * 'return; yield' isn't considered covered * Update newsfragments/3108.bugfix.rst * [pre-commit.ci] auto fixes from pre-commit.com hooks --------- Co-authored-by: EXPLOSION <[email protected]> Co-authored-by: oremanj <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
- Loading branch information
1 parent
13d4bad
commit 57452ad
Showing
15 changed files
with
480 additions
and
149 deletions.
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
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,2 @@ | ||
:func:`inspect.iscoroutinefunction` and the like now give correct answers when | ||
called on KI-protected functions. |
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,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. |
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
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.