Skip to content

Defer KI if trio is doing IO #3233

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

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

A5rocks
Copy link
Contributor

@A5rocks A5rocks commented Mar 28, 2025

Supersedes #1537.

As with that, fixes #151, first step of #733.

Additionally, fixes part of #3007 (not intentionally, just because it has to be done in order to still raise a KI. I should add a test.).

@A5rocks
Copy link
Contributor Author

A5rocks commented Mar 28, 2025

codecov failure doesn't make any sense and seems to be a recent thing. I'm inclined to believe it's some change in how they normalize file names but I don't think it's worth chasing down for now.

Copy link

codecov bot commented Apr 11, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.95275%. Comparing base (d65d3f6) to head (261e2b2).
Report is 11 commits behind head on main.

Additional details and impacted files
@@                 Coverage Diff                  @@
##                 main       #3233         +/-   ##
====================================================
- Coverage   100.00000%   99.95275%   -0.04726%     
====================================================
  Files             124         124                 
  Lines           19047       19047                 
  Branches         1287        1287                 
====================================================
- Hits            19047       19038          -9     
- Misses              0           8          +8     
- Partials            0           1          +1     
Files with missing lines Coverage Δ
src/trio/_core/_run.py 99.11417% <100.00000%> (-0.88583%) ⬇️
src/trio/_core/_tests/test_guest_mode.py 100.00000% <100.00000%> (ø)
src/trio/_core/_tests/test_ki.py 100.00000% <100.00000%> (ø)
src/trio/_repl.py 100.00000% <100.00000%> (ø)
src/trio/_threads.py 100.00000% <ø> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Member

@jakkdl jakkdl left a comment

Choose a reason for hiding this comment

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

Is the change to the abort parameter tightly bound to the other changes in this PR? Can it be pulled out into a separate PR?

This is a daunting PR to review, with one former PR and 4 related issues, and changes in 23 files, and it might be more manageable if it got split up.

It'd also be nice if the PR summarized the state of discussion, I don't know if KI-deferral has been unanimously agreed to be the better way to do it, or if there's up- & downsides.

Sorry for the non-review review <3

`~trio.Cancelled` exception, but we may use this mechanism to
raise other exceptions in the future; you should raise whatever
you're given.) Either of the approaches sketched below can
work::
Copy link
Member

Choose a reason for hiding this comment

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

is this block of text modified? Or just reformatted? It's hard to see in the diff

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Modified, specifically the second to last sentance (which turns into two). I copied this over from the old PR which might explain the formatting...

@A5rocks
Copy link
Contributor Author

A5rocks commented May 5, 2025

I can do the change to abort fn as a follow up -- it needs this change because the reason it's a function is because KI can be raised (which this change stops), but this change doesn't depend on it.

This isn't so much a summary but see #733 (comment) (this is ~just about that issue, other issues being closed is just because this is a Good Idea and unlocks easy fixes).

Copy link
Contributor Author

@A5rocks A5rocks left a comment

Choose a reason for hiding this comment

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

Alright, I removed the abort function signature change.

`~trio.Cancelled` exception, but we may use this mechanism to
raise other exceptions in the future; you should raise whatever
you're given.) Either of the approaches sketched below can
work::
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Modified, specifically the second to last sentance (which turns into two). I copied this over from the old PR which might explain the formatting...

Copy link
Member

@jakkdl jakkdl left a comment

Choose a reason for hiding this comment

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

seems fine as far as I can tell~

@@ -351,6 +351,8 @@ async def to_thread_run_sync(
if limiter is None:
limiter = current_default_thread_limiter()

# TODO: cancel_register can probably be a single element tuple for typing reasons
Copy link
Member

Choose a reason for hiding this comment

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

This helps in stopping people from indexing above 0, but it breaks a bunch of current code that manipulates the content of the list. Ideally it'd be some minimalist wrapper class.

Copy link
Contributor

Choose a reason for hiding this comment

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

would a deque with maxlen=1 help?

Copy link
Member

Choose a reason for hiding this comment

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

I wouldn't expect typing to take the maxlen into account

return
self.main_task._attempt_delivery_of_pending_ki()
with suppress(RunFinishedError):
self.entry_queue.run_sync_soon(self.main_task_nursery.cancel_scope.cancel)
Copy link
Member

Choose a reason for hiding this comment

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

nice, this will be easy to harmonize with #3232 🚀

_core.run(check_protected_kill)

# TODO: be consistent about providing Cancelled tree as __context__
Copy link
Member

Choose a reason for hiding this comment

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

what's required for this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

How should shielding interact with restrict_keyboard_interrupt_to_checkpoints?
3 participants