Async Techniques and Examples in Python Transcripts
Chapter: Built on asyncio
Lecture: Concept: Trio nurseries
0:00 Let's review our core concepts around Trio.
0:02 Trio is independent async await capable
0:07 library that is entirely independent
0:09 of Python's built in asyncio library.
0:12 That whole loop of structure and
0:14 underlying things has nothing to do with Trio.
0:17 So Trio is it's own thing from scratch.
0:19 And the reason it's like that is they want to make
0:22 sure they have complete control over how stuff
0:25 executes, the cancellation, the error handling
0:26 all of those types of things.
0:29 So here's a general use case, I'd like to go an generate
0:32 some work and consume some work with the
0:34 producer consumer style and I want to maybe even
0:37 let those pieces kick off sub child tasks and so on.
0:41 And I'd like to either do all the work and finish
0:43 successfully in five seconds or I want them
0:46 to be canceled if they have still pending work.
0:49 So we just create one with block for the move on part
0:51 that's the time out and then the async with block.
0:55 One's async, one is not, be careful there.
0:58 The async with block to open the nursery
1:00 kick off all the work and either that's going to block
1:02 until it's finished, it's going to block until
1:04 you cancel or it's going to block until one of them has an
1:06 error in which case it'll cancel all the
1:08 running and not yet started tasks.
1:12 It's a really simple coordination
1:13 concept around async work.