Python 3, an Illustrated Tour Transcripts
Chapter: Asynchronous Programming
Lecture: asyncio Tips and Tools
Login or
purchase this course
to watch this video and the rest of the course contents.
0:00
If you want to use asyncio you need to be aware that your code needs to be infested or whatnot.
0:06
It needs to call await and use other code that allows you to wait and run other code or is interruptable.
0:14
And so there are a bunch of libraries on GitHub that are compatible with asyncio. Tips for debugging you can use pdb to debug,
0:22
if you've tried to use pdb with threading, it can be a pain because it may or may not stop and then it may be confusing
0:29
because Python is trying to run while you're trying to do pdb or whatnot. But in this case because there's only one process running
0:37
you can use pdb to debug. There's a couple other tools you might want to look into these aren't included in the standard library, but they're there,
0:45
aioconsole and aiomonitor, these allow you to have a repl that is asyncio aware and allows you to directly call await and async coroutines
0:56
rather than having to put them into loops. So it's a little bit easier to debug that way. If you're doing testing you need to have an event loop
1:04
and your testing framework needs to be aware of that so you can roll your own or if you don't want to roll your own
1:09
you can take advantage of stuff that's already there. So there's one called asynctest, this is on top of the unit test framework
1:15
and there's another called pytest asyncio which is compatible with pytest. We've looked at a lot in this section.
1:23
We've talked about asyncio, what it means to be concurrent versus parallel and how you can use non-blocking code to not wait if you're using asyncio.