Skip to content

Isolate#22

Merged
patrick-kidger merged 4 commits intodevfrom
isolate
Mar 14, 2026
Merged

Isolate#22
patrick-kidger merged 4 commits intodevfrom
isolate

Conversation

@patrick-kidger
Copy link
Copy Markdown
Owner

Supersedes #20, #21. @aburgm – continuing the conversation from #21. I've squashed your commits and then made some tweaks on top.

I've been noodling on the design here a bit, and I think I've refined it a little further from where we last had it. In particular I'd direct your attention to the devdoc I've added here, which you should treat as if it was the PR description.

WDYT? Right now I'm not feeling 100% sold on this, I'm wondering if it all feels perhaps a bit more advanced than 'tiny'io is really about supporting out-of-the-box.

@aburgm
Copy link
Copy Markdown
Contributor

aburgm commented Mar 11, 2026

Hm, I'm wondering what makes this inherently more complicated than integration with other event loops such as trio?

Note that we definitely need some means of placing things on the main loop (not just the isolated loop), as e.g. we may want an isolated coroutine to consume some input made available by the main loop... a dependency typically expressed as yield some_coroutine.

What if we started with a limited API where this is not possible? (alas I think for my usecase it would be sufficient)

Also to note is that isolate() is only implemented by means of public tinyio APIs, so it doesn't have to live in tinyio proper. Maybe it's enough to add it as an example for people to copy, and then they can choose whatever semantics works best for their usecase (with the downside that then they have to work through the details).

@patrick-kidger
Copy link
Copy Markdown
Owner Author

Hm, I'm wondering what makes this inherently more complicated than integration with other event loops such as trio?

So the main issue is that with different event loops, there is no way in which the same coroutine can appear on both loops. However when both loops are tinyio loops, then this is possible. Or at the very least – it is possible for a user to express that intent. We then need to decide how we should handle that, or how we should detect it and error out.

What if we started with a limited API where this is not possible?

So that's actually pretty much the design of the current implementation, actually. There's now an entirely separate tinyio.copy to handle this detail, and tinyio.isolate doesn't try to do it itself.

Also to note is that isolate() is only implemented by means of public tinyio APIs, so it doesn't have to live in tinyio proper. Maybe it's enough to add it as an example for people to copy, and then they can choose whatever semantics works best for their usecase (with the downside that then they have to work through the details).

Yup, I considered this. On balance I lean towards including it, as I can see that working through the details is likely to lead a user into a footgun. Better to handle it ourselves and carefully wall of the places where mistakes can be made.

(Side note, I think one thing that would complement this well is a way to schedule work on the tinyio loop event even after an error has occurred. It's a bit of a side project, but I'm noodling on some ideas in this direction.)


Any commentary on the PR let me know, otherwise I'm happy to merge this :)

Copy link
Copy Markdown
Contributor

@aburgm aburgm left a comment

Choose a reason for hiding this comment

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

Thanks for the explanations! I don't have major comments, I agree the current approach is the most prudent for now.

aburgm and others added 2 commits March 14, 2026 12:06
This allows to isolate them from each other so that an exception in a
nested group does not affect coroutines running outside.

Make test with exceptions work

Use isolate() instead of nest() as public API

Explicit boolean check and add exception_group parameter

Return exception instead of calling `cleanup` with it
@patrick-kidger patrick-kidger merged commit 8badf1b into dev Mar 14, 2026
2 checks passed
@patrick-kidger patrick-kidger deleted the isolate branch March 14, 2026 11:17
@patrick-kidger
Copy link
Copy Markdown
Owner Author

And merged, with a 0.4.0 release! :)

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