Skip to content

Conversation

Zac-HD
Copy link
Member

@Zac-HD Zac-HD commented Sep 17, 2025

We dropped this handler from #3197, presumably because the tests (...or production patterns) which trigger it are fairly esoteric. The if not send_chan._state.open_receive_channels: break clause is actually new, but lets us skip a pointless __anext__ call in many cases which is a nice perf win.

I just wish I'd noticed this in time for #3325, rather than when pulling it in the new version 🤦‍♂️

@Zac-HD Zac-HD requested a review from A5rocks September 17, 2025 05:00
@Zac-HD Zac-HD force-pushed the close-on-broken-resource branch 3 times, most recently from b7a4513 to ed7c6dc Compare September 17, 2025 05:18
@Zac-HD Zac-HD force-pushed the close-on-broken-resource branch from ed7c6dc to 4407451 Compare September 17, 2025 05:29
@python-trio python-trio deleted a comment from codecov bot Sep 17, 2025
@A5rocks
Copy link
Contributor

A5rocks commented Sep 17, 2025

Just realized the "Encountered exception during cleanup of generator object ..." exception group... contains the exception group with multiple exceptions!? That looks weird when printed! I guess I should make a new issue about that. (unless that behavior makes perfect sense to you?)

Copy link
Contributor

@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.

I have a question and a comment about the tests, but this makes sense.

(I have the possibly strange opinion that we should one day have service nurseries, meaning that trio.as_safe_channel would be implemented s.t. the task calling the async generator should never raise... which actually runs counter to "I can close the channel" now that I think about it. Well, that's for another day.)

yield # pragma: no cover

async with agen() as chan:
await chan.aclose()
Copy link
Contributor

Choose a reason for hiding this comment

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

Huh, it's a bit unintuitive to me that it's possible to not run any code within the async generator. But that can happen in sync generators too so I guess it's fine.

@Zac-HD
Copy link
Member Author

Zac-HD commented Sep 17, 2025

Just realized the "Encountered exception during cleanup of generator object ..." exception group... contains the exception group with multiple exceptions!? That looks weird when printed! I guess I should make a new issue about that. (unless that behavior makes perfect sense to you?)

hmm, we could instead use .add_note(""Encountered exception during cleanup ...") on the group with multiple exceptions? The status quo is not ideal IMO, but since we're hopefully not going to see that outside of a bug or keyboard-interrupt etc I don't think it's a big deal.

@A5rocks
Copy link
Contributor

A5rocks commented Sep 17, 2025

The status quo is not ideal IMO, but since we're hopefully not going to see that outside of a bug or keyboard-interrupt etc I don't think it's a big deal.

Or

async def test8() -> None:
    @trio.as_safe_channel
    async def agen():
        await chan.aclose()
        raise ValueError()
        yield

    async with agen() as chan:
        async for _ in chan:
            pass

(I think. When I run that on main we drop the ValueError sometimes (I guess this is the "missed-alarm" thing you mentioned?) which is uh, awful.)

Anyways, moved that to #3332.

@Zac-HD
Copy link
Member Author

Zac-HD commented Sep 17, 2025

When I run that on main we drop the ValueError sometimes (I guess this is the "missed-alarm" thing you mentioned?) which is uh, awful.

yeah, we should probably have an open issue for that in fact.

@A5rocks
Copy link
Contributor

A5rocks commented Sep 18, 2025

Yeah turns out this PR doesn't fix that case so I've made #3333. I'm fine with this PR not fixing that.

@Zac-HD
Copy link
Member Author

Zac-HD commented Sep 18, 2025

OK, merging this as an improvement on the status quo; I'd rather not block on a general fix to the cancellation problem.

@Zac-HD Zac-HD merged commit 0f975c3 into python-trio:main Sep 18, 2025
43 checks passed
Copy link

codecov bot commented Sep 18, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00000%. Comparing base (0aa5ee3) to head (4407451).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@               Coverage Diff               @@
##                 main        #3331   +/-   ##
===============================================
  Coverage   100.00000%   100.00000%           
===============================================
  Files             125          125           
  Lines           19547        19582   +35     
  Branches         1336         1341    +5     
===============================================
+ Hits            19547        19582   +35     
Files with missing lines Coverage Δ
src/trio/_channel.py 100.00000% <100.00000%> (ø)
src/trio/_tests/test_channel.py 100.00000% <100.00000%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

2 participants