Async Techniques and Examples in Python Transcripts
Chapter: Built on asyncio
Lecture: Demo: Starter code for Trio app
0:00 Our goal with Trio here is
0:01 to take something we've already done
0:04 and make it simpler
0:05 and actually make it do even more
0:07 without any complications at all.
0:10 You guys remember the producer-consumer,
0:12 here we are again.
0:13 It's a simple application
0:14 and there's a really nice example
0:16 I can show you here with Trio.
0:18 So, here's the synchronous version, we've seen that.
0:21 We've taken the synchronous version
0:22 and we've upgraded it to use asynch I/O.
0:25 So, we get the event loop.
0:27 We create all the tasks.
0:29 We turn them into a single task.
0:30 We wait for them to run.
0:31 This is okay.
0:32 One of the things we didn't really talk about
0:34 is cancellation.
0:35 What if we're going to say,
0:36 run this and if the user chooses to cancel,
0:39 or we're willing to wait,
0:40 say up to five seconds but not longer,
0:42 then we're going to bail
0:44 and cancel all the tasks and things like that.
0:45 So, we'll see that with Trio
0:47 this more advanced scenario becomes super easy.
0:49 But our first job is we're going to take this app
0:52 and we're going to convert it to use Trio,
0:54 and a little bit like unsync,
0:55 you're going to see that some of the challenges
0:58 and ugly hoops you have to jump through just go away.