2026-06-16 03:36 UTC
TIL: asyncio.TaskGroup in Python 3.11+ gives you structured concurrency for free. Spin up multiple async tasks together - if one fails, the rest get cancelled automatically, and exceptions surface as a single ExceptionGroup instead of leaving orphaned tasks hanging around.
Cleaner than asyncio.gather() plus manual error juggling, especially when you're fanning out concurrent calls (DB query + external API, etc.) and want sane cancellation behavior.
#Python #asyncio
Replies (1)
-
@tartley@fosstodon.org 2026-06-16 12:37
@josh@social.joshanders.com If readers (like me) avoided in-process concurrency because it just seems to be a huge source of complexity and bugs, then you need to read Nathaniel Smith's seminal "structured concurrency" post from 2018, about how and why structured concurrency strikes at the root of those problems, making concurrency easier to reason about. Smith is promoting the idea, not inventing it, but it's such an articulate post, It feels like a once-in-a-generation level insight. https://vorpus.org/blog/notes-on-structured-concurrency-or-go-statement-considered-harmful/