title
Asyncio - Asynchronous programming with coroutines - Intermediate Python Programming p.26

description
Welcome to an Asyncio with Python tutorial. This tutorial will be specifically for Python 3.5+, using the latest asyncio keywords. Asyncio is the standard library package with Python that aims to help you write asynchronous code by giving you an easy way to write, execute, and structure your coroutines. The Asyncio library is for concurrency, which is not to be confused with parallelism. Text tutorials and sample code: https://pythonprogramming.net/asyncio-basics-intermediate-python-tutorial/ Discord: https://discordapp.com/invite/3jCqXJj Support the content: https://pythonprogramming.net/support-donate/ Twitter: https://twitter.com/sentdex Facebook: https://www.facebook.com/pythonprogramming.net/ Twitch: https://www.twitch.tv/sentdex G+: https://plus.google.com/+sentdex

detail
{'title': 'Asyncio - Asynchronous programming with coroutines - Intermediate Python Programming p.26', 'heatmap': [{'end': 551.88, 'start': 528.363, 'weight': 0.716}, {'end': 1133.815, 'start': 1114.663, 'weight': 1}], 'summary': 'Tutorial series on intermediate python programming covers using asyncio for asynchronous programming, converting functions into coroutines, handling asynchronous requests with aio http, and important concepts like event loop management, exception handling, and creating asynchronous loops.', 'chapters': [{'end': 122.23, 'segs': [{'end': 32.402, 'src': 'embed', 'start': 1.769, 'weight': 1, 'content': [{'end': 5.171, 'text': "what's going on everybody and welcome to another intermediate python tutorial.", 'start': 1.769, 'duration': 3.402}, {'end': 11.533, 'text': "in this tutorial what we're going to be talking about is asyncio or asyncio, depending on which way you want to say it.", 'start': 5.171, 'duration': 6.362}, {'end': 12.334, 'text': "I won't judge,", 'start': 11.533, 'duration': 0.801}, {'end': 32.402, 'text': "other people will and what asyncio is for is for asynchronous programming and probably the best way to kind of understand concurrency in basically any programming language is it's often confused with Doing something in parallel.", 'start': 12.334, 'duration': 20.068}], 'summary': 'This tutorial covers asyncio for asynchronous programming in python.', 'duration': 30.633, 'max_score': 1.769, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/BI0asZuqFXM/pics/BI0asZuqFXM1769.jpg'}, {'end': 88.837, 'src': 'embed', 'start': 62.525, 'weight': 0, 'content': [{'end': 70.93, 'text': 'So, no, you stop your run, you suspend your run and you bend over, you tie your shoe, you finish tying your shoe and you get back to your run.', 'start': 62.525, 'duration': 8.405}, {'end': 75.693, 'text': "okay?. And this is you're doing these two tasks, right?", 'start': 70.93, 'duration': 4.763}, {'end': 79.655, 'text': "You're able to tie your shoe and you're able to run concurrently.", 'start': 76.213, 'duration': 3.442}, {'end': 82.472, 'text': 'So the same thing is true with programming.', 'start': 80.33, 'duration': 2.142}, {'end': 88.837, 'text': "Let's say you've got a web page and that web page needs to load a whole bunch of elements.", 'start': 82.512, 'duration': 6.325}], 'summary': 'Concurrently perform tasks like tying shoes and running, similar to programming a web page with multiple elements.', 'duration': 26.312, 'max_score': 62.525, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/BI0asZuqFXM/pics/BI0asZuqFXM62525.jpg'}], 'start': 1.769, 'title': 'Using asyncio in python', 'summary': 'Introduces asyncio for asynchronous programming, explaining concurrency, differentiating from parallel programming, and emphasizing its importance in web development.', 'chapters': [{'end': 122.23, 'start': 1.769, 'title': 'Asyncio in python', 'summary': 'Introduces asyncio for asynchronous programming by using real-life examples to explain the concept of concurrency, illustrating how it differs from parallel programming, and highlighting its significance in web development.', 'duration': 120.461, 'highlights': ['Asynchronous programming in Python is demonstrated through real-life examples, such as tying a shoe while on a jog and loading web elements concurrently, emphasizing the importance of handling tasks concurrently without necessarily doing them in parallel.', 'The concept of concurrency in programming is clarified by comparing it to handling multiple tasks at once, such as tying a shoe and running, to illustrate the ability to perform multiple tasks concurrently.', "The significance of asyncio in web development is highlighted by demonstrating how synchronous loading can lead to the entire webpage hanging when waiting for a non-responsive server, while asynchronous loading allows other elements to load concurrently, mitigating the impact of a non-responsive server on the webpage's performance."]}], 'duration': 120.461, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/BI0asZuqFXM/pics/BI0asZuqFXM1769.jpg', 'highlights': ["The significance of asyncio in web development is highlighted by demonstrating how synchronous loading can lead to the entire webpage hanging when waiting for a non-responsive server, while asynchronous loading allows other elements to load concurrently, mitigating the impact of a non-responsive server on the webpage's performance.", 'Asynchronous programming in Python is demonstrated through real-life examples, such as tying a shoe while on a jog and loading web elements concurrently, emphasizing the importance of handling tasks concurrently without necessarily doing them in parallel.', 'The concept of concurrency in programming is clarified by comparing it to handling multiple tasks at once, such as tying a shoe and running, to illustrate the ability to perform multiple tasks concurrently.']}, {'end': 442.208, 'segs': [{'end': 181.502, 'src': 'embed', 'start': 122.23, 'weight': 1, 'content': [{'end': 130.515, 'text': 'you could be doing other things other than just sitting there literally doing nothing and waiting on a response.', 'start': 122.23, 'duration': 8.285}, {'end': 147.635, 'text': "Now, what I'd like to do here is just I think we're just going to start with a really basic function and then we're going to turn it into a coroutine.", 'start': 135.379, 'duration': 12.256}, {'end': 150.96, 'text': 'If I say goroutine in this tutorial, forgive me.', 'start': 147.876, 'duration': 3.084}, {'end': 158.186, 'text': 'My first experience with concurrency was actually with goroutines in Go.', 'start': 153.342, 'duration': 4.844}, {'end': 162.049, 'text': 'And so I just call it coroutines goroutines.', 'start': 158.586, 'duration': 3.463}, {'end': 162.89, 'text': 'You might not even notice.', 'start': 162.089, 'duration': 0.801}, {'end': 166.933, 'text': "Anyways, let's just say this is the function that we're going to use.", 'start': 163.51, 'duration': 3.423}, {'end': 170.756, 'text': "So all it is, is it's just going to find some numbers.", 'start': 167.293, 'duration': 3.463}, {'end': 173.938, 'text': 'And by the way, yes, I just copy and pasted this function.', 'start': 170.856, 'duration': 3.082}, {'end': 181.502, 'text': "I'll put a link in the description to the text based version and you can grab this function or you can write it as I'm talking if you want.", 'start': 175.699, 'duration': 5.803}], 'summary': "Tutorial on converting a basic function into a coroutine with a reference to go's goroutines.", 'duration': 59.272, 'max_score': 122.23, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/BI0asZuqFXM/pics/BI0asZuqFXM122230.jpg'}, {'end': 368.145, 'src': 'embed', 'start': 233.228, 'weight': 0, 'content': [{'end': 238.871, 'text': 'copy and paste that and that will be uh, just so i match the text space right up.', 'start': 233.228, 'duration': 5.643}, {'end': 251.557, 'text': "let's do 508 thousand thirty four, one through one, one, three, thirty four, one, three, and then i'm just going to copy, paste, paste, make that two,", 'start': 238.871, 'duration': 12.686}, {'end': 261.781, 'text': "three, uh, 1052, 3210, and then we'll do 503.", 'start': 251.557, 'duration': 10.224}, {'end': 264.723, 'text': "okay, so now we've got our main function here.", 'start': 261.781, 'duration': 2.942}, {'end': 280.332, 'text': "and then, um, just for in case someone wanted to import this amazing script, if name equals main, we would have just let's just run the main function.", 'start': 264.723, 'duration': 15.609}, {'end': 286.778, 'text': 'so so with that you also, you know, you can change this function to be anything you want.', 'start': 280.332, 'duration': 6.446}, {'end': 295.166, 'text': 'you can, you can have it doing Fibonacci stuff, if you really want to be like everybody, or you could do anything you want.', 'start': 286.778, 'duration': 8.388}, {'end': 307.678, 'text': 'really, I will say if you are interested in doing truly HTTP tasks, you can look into AIO HTTP for doing asynchronous requesting and stuff like that.', 'start': 295.166, 'duration': 12.512}, {'end': 312.441, 'text': "So that's why we're not going to use that for this example, but just take note.", 'start': 308.158, 'duration': 4.283}, {'end': 316.603, 'text': 'So now that we have this, divs one, two, three, okay.', 'start': 313.081, 'duration': 3.522}, {'end': 321.906, 'text': "What we want to do is we could even, let's just run this real quick, just see what we're dealing with.", 'start': 317.764, 'duration': 4.142}, {'end': 331.411, 'text': "So as you can see, this whole script runs, it's about 0.3 seconds, and we can see it runs in the order that we called it, basically.", 'start': 322.206, 'duration': 9.205}, {'end': 342.63, 'text': "So it runs divs one, it finds, it just starts iterating through 508,000, finding all instances where we have a number that's divisible by 34,113.", 'start': 331.451, 'duration': 11.179}, {'end': 346.713, 'text': 'So it does this one and then it does this one and then it does this one.', 'start': 342.631, 'duration': 4.082}, {'end': 352.096, 'text': 'So what could we do to convert this to be asynchronous?', 'start': 347.434, 'duration': 4.662}, {'end': 353.317, 'text': 'And why might we want to do that?', 'start': 352.136, 'duration': 1.181}, {'end': 356.458, 'text': 'Well, for example, what if this was instead this right?', 'start': 353.357, 'duration': 3.101}, {'end': 357.199, 'text': 'And we ran this.', 'start': 356.499, 'duration': 0.7}, {'end': 360.341, 'text': "It's going to hang on this one,", 'start': 357.639, 'duration': 2.702}, {'end': 368.145, 'text': 'where we actually really could have found the answers to these two and then come back to this one and spent about the same amount of time, right?', 'start': 360.341, 'duration': 7.804}], 'summary': 'The script iterates through numbers to find instances divisible by 34,113, running in about 0.3 seconds. consider converting it to asynchronous for improved efficiency.', 'duration': 134.917, 'max_score': 233.228, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/BI0asZuqFXM/pics/BI0asZuqFXM233228.jpg'}], 'start': 122.23, 'title': 'Python concurrency and aio http', 'summary': 'Discusses converting a function into a coroutine in python concurrency, along with a demonstration. it also introduces synchronous and asynchronous execution in python, highlighting aio http for handling asynchronous requests and the challenges of dealing with large packages like aio http.', 'chapters': [{'end': 295.166, 'start': 122.23, 'title': 'Concurrency in python tutorial', 'summary': 'Discusses the process of converting a basic function into a coroutine in the context of a python tutorial on concurrency, with a demonstration of a sample function and its application to find numbers within a range and print the results.', 'duration': 172.936, 'highlights': ['The tutorial begins with a discussion on converting a basic function into a coroutine, with a reference to the use of goroutines in Go for concurrency.', 'The function demonstrated in the tutorial involves finding numbers within a given range and performing division operations, with the ability to customize the function for different purposes.', 'The main function is illustrated with specific inputs and outputs, showcasing the practical application of the coroutine in Python for concurrency.', 'The tutorial emphasizes the flexibility of the function, allowing users to modify it for various purposes such as performing Fibonacci calculations.']}, {'end': 442.208, 'start': 295.166, 'title': 'Introduction to aio http', 'summary': "Introduces the concept of synchronous and asynchronous execution in python, demonstrating a script's synchronous behavior, the potential benefits of async execution, and the introduction of aio http for handling asynchronous requests, while highlighting the need for async io and the challenges of dealing with large packages like aio http.", 'duration': 147.042, 'highlights': ['The script runs synchronously, taking about 0.3 seconds to iterate through 508,000 instances in the order they are called.', 'The need for asynchronous execution is highlighted by the potential time savings, where tasks could run concurrently instead of sequentially, reducing wait times.', 'Introduction to AIO HTTP is discussed, with a mention of the complexity of the package and the need for simpler documentation for beginners.', 'The drawbacks of using threading or multiprocessing for async execution are mentioned due to the additional complexities involved.']}], 'duration': 319.978, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/BI0asZuqFXM/pics/BI0asZuqFXM122230.jpg', 'highlights': ['The tutorial emphasizes the flexibility of the function, allowing users to modify it for various purposes such as performing Fibonacci calculations.', 'The function demonstrated in the tutorial involves finding numbers within a given range and performing division operations, with the ability to customize the function for different purposes.', 'The main function is illustrated with specific inputs and outputs, showcasing the practical application of the coroutine in Python for concurrency.', 'The tutorial begins with a discussion on converting a basic function into a coroutine, with a reference to the use of goroutines in Go for concurrency.', 'The need for asynchronous execution is highlighted by the potential time savings, where tasks could run concurrently instead of sequentially, reducing wait times.', 'The script runs synchronously, taking about 0.3 seconds to iterate through 508,000 instances in the order they are called.', 'Introduction to AIO HTTP is discussed, with a mention of the complexity of the package and the need for simpler documentation for beginners.', 'The drawbacks of using threading or multiprocessing for async execution are mentioned due to the additional complexities involved.']}, {'end': 639.524, 'segs': [{'end': 551.88, 'src': 'heatmap', 'start': 442.248, 'weight': 0, 'content': [{'end': 445.529, 'text': "But anyway, there's a whole bunch there for you.", 'start': 442.248, 'duration': 3.281}, {'end': 448.87, 'text': "it's basically an api over concurrency that you know.", 'start': 445.928, 'duration': 2.942}, {'end': 450.751, 'text': 'you you really could use yield from.', 'start': 448.87, 'duration': 1.881}, {'end': 456.215, 'text': "you could use the like go, co-routine, decorators and stuff like that, and you wouldn't necessarily.", 'start': 450.751, 'duration': 5.464}, {'end': 462.639, 'text': "you don't have to use async io to do concurrency, it's just, it's a very large package to help you do it.", 'start': 456.215, 'duration': 6.424}, {'end': 466.882, 'text': 'so anyways, getting back to the code.', 'start': 462.639, 'duration': 4.243}, {'end': 469.663, 'text': 'how do we convert something to being asynchronous?', 'start': 466.882, 'duration': 2.781}, {'end': 482.52, 'text': 'well, first of all, the main conversion is, rather than def something, you async, def something, and that basically notifies python.', 'start': 469.663, 'duration': 12.857}, {'end': 485.062, 'text': 'hey, this is a co routine.', 'start': 482.52, 'duration': 2.542}, {'end': 490.966, 'text': "so the first step that we're going to make is actually we're just going to async both of these functions.", 'start': 485.062, 'duration': 5.904}, {'end': 500.532, 'text': "now the next thing that we want to do is we want to go ahead and bring whoops, we're going to bring in, import async io.", 'start': 490.966, 'duration': 9.566}, {'end': 506.549, 'text': 'That way we can use some of these helper functions, basically with AsyncIO.', 'start': 501.584, 'duration': 4.965}, {'end': 516.438, 'text': 'So now what we want to go ahead and do is once you have your coroutines, we need some sort of loop.', 'start': 507.63, 'duration': 8.808}, {'end': 521.677, 'text': "Right now we're just running main and, in theory, main itself.", 'start': 517.111, 'duration': 4.566}, {'end': 527.302, 'text': "you would call this at the moment probably a main loop, just because it's going to run through that little block of code.", 'start': 521.677, 'duration': 5.625}, {'end': 534.388, 'text': 'But what we want to do with asyncIO is we need to establish the main loop, which is basically your event loop,', 'start': 528.363, 'duration': 6.025}, {'end': 538.732, 'text': "and then you're going to add in tasks and tell that loop how to run and all that.", 'start': 534.388, 'duration': 4.344}, {'end': 541.235, 'text': "So now what we're going to do is we're going to come down here,", 'start': 538.832, 'duration': 2.403}, {'end': 545.536, 'text': "and this is where we're going to stuff in At least the initial definitions for our loop.", 'start': 541.235, 'duration': 4.301}, {'end': 551.88, 'text': "So we're going to say loop equals asyncio.get underscore event loop.", 'start': 545.576, 'duration': 6.304}], 'summary': 'Using asyncio to convert functions to asynchronous, incorporating event loop and tasks for concurrency.', 'duration': 98.987, 'max_score': 442.248, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/BI0asZuqFXM/pics/BI0asZuqFXM442248.jpg'}, {'end': 625.279, 'src': 'embed', 'start': 593.727, 'weight': 4, 'content': [{'end': 601.013, 'text': "So again, there's no way I can cover this entire package in one video, um, or even a few videos.", 'start': 593.727, 'duration': 7.286}, {'end': 603.615, 'text': 'just know the docs exist.', 'start': 601.013, 'duration': 2.602}, {'end': 609.779, 'text': "so so anyways, run until complete and then, whenever you're done, um, you can you do a loop.close.", 'start': 603.615, 'duration': 6.164}, {'end': 611.4, 'text': "i'm actually not 100 confident.", 'start': 609.779, 'duration': 1.621}, {'end': 614.883, 'text': "run until complete is going to require a loop.close, but we'll go for it.", 'start': 611.4, 'duration': 3.483}, {'end': 625.279, 'text': "Also, you'll see a lot of times in code it's going to be like try to do the loop stuff except do some logging, not really a pass.", 'start': 615.535, 'duration': 9.744}], 'summary': "The package cannot be fully covered in one video, and 'run until complete' may need a loop.close.", 'duration': 31.552, 'max_score': 593.727, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/BI0asZuqFXM/pics/BI0asZuqFXM593727.jpg'}], 'start': 442.248, 'title': 'Asynchronous conversion in python', 'summary': 'Discusses converting functions to asynchronous using async def and importing asyncio, establishing the main event loop, and running the main coroutine. it also covers the usage of the asyncio package, including run until complete and loop close functions, and the importance of managing the event loop and handling exceptions.', 'chapters': [{'end': 563.247, 'start': 442.248, 'title': 'Asynchronous conversion in python', 'summary': 'Discusses converting functions to asynchronous using async def and importing asyncio, then establishing the main event loop and running the main coroutine.', 'duration': 120.999, 'highlights': ["The main conversion process involves using 'async def' to notify Python that a function is a coroutine and importing 'asyncio' for utilizing helper functions, leading to the establishment of the main event loop.", "The chapter emphasizes that async IO is not the sole method for concurrency in Python, as it provides multiple options including 'yield from', 'go' coroutine, and decorators for concurrency.", 'The importance of establishing the main event loop and adding tasks to instruct the loop on how to run is highlighted for managing asynchronous operations.', "The significance of initializing the event loop using 'asyncio.get_event_loop' is noted to run the main coroutine until it's completed."]}, {'end': 639.524, 'start': 566.946, 'title': 'Asyncio package usage', 'summary': 'Covers the usage of the asyncio package, including run until complete and loop close functions, along with the importance of managing the event loop and handling exceptions.', 'duration': 72.578, 'highlights': ['The asyncio package usage involves functions like run until complete, run forever, and loop close, with the need for proper event loop management and exception handling.', 'There is no way to cover the entire asyncio package in one video, emphasizing the extensive functionality and documentation available for further exploration.', 'It is important to always close off the event loop using loop.close, and handle exceptions properly to avoid issues during asynchronous operations.']}], 'duration': 197.276, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/BI0asZuqFXM/pics/BI0asZuqFXM442248.jpg', 'highlights': ["The main conversion process involves using 'async def' to notify Python that a function is a coroutine and importing 'asyncio' for utilizing helper functions, leading to the establishment of the main event loop.", 'The importance of establishing the main event loop and adding tasks to instruct the loop on how to run is highlighted for managing asynchronous operations.', "The significance of initializing the event loop using 'asyncio.get_event_loop' is noted to run the main coroutine until it's completed.", 'The asyncio package usage involves functions like run until complete, run forever, and loop close, with the need for proper event loop management and exception handling.', 'It is important to always close off the event loop using loop.close, and handle exceptions properly to avoid issues during asynchronous operations.', "The chapter emphasizes that async IO is not the sole method for concurrency in Python, as it provides multiple options including 'yield from', 'go' coroutine, and decorators for concurrency."]}, {'end': 1271.383, 'segs': [{'end': 674.559, 'src': 'embed', 'start': 639.645, 'weight': 0, 'content': [{'end': 640.545, 'text': 'Cool General exceptions.', 'start': 639.645, 'duration': 0.9}, {'end': 646.636, 'text': "Okay Anyways, okay, so now we've done, so we've got the loop.", 'start': 640.605, 'duration': 6.031}, {'end': 650.278, 'text': 'Now what we have to do is we need to insert stuff into that loop.', 'start': 647.036, 'duration': 3.242}, {'end': 652.78, 'text': "So all it's going to do right now is run the main coroutine.", 'start': 650.318, 'duration': 2.462}, {'end': 656.002, 'text': 'okay?. But the coroutine is running.', 'start': 652.78, 'duration': 3.222}, {'end': 659.604, 'text': 'basically these functions still synchronously right?', 'start': 656.002, 'duration': 3.602}, {'end': 662.145, 'text': 'It still says just run one, two and three.', 'start': 659.684, 'duration': 2.461}, {'end': 664.527, 'text': 'Instead what we want to do is we want to add them in.', 'start': 662.546, 'duration': 1.981}, {'end': 674.559, 'text': 'So rather than find divisibles, we want to say, rather than just running just that function, we actually want to say loop dot create underscore task.', 'start': 665.157, 'duration': 9.402}], 'summary': 'Discussing the need to insert tasks into a loop for synchronous execution.', 'duration': 34.914, 'max_score': 639.645, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/BI0asZuqFXM/pics/BI0asZuqFXM639645.jpg'}, {'end': 738.829, 'src': 'embed', 'start': 695.737, 'weight': 1, 'content': [{'end': 700.379, 'text': "Now I'm trying to think, I think this is runnable at this stage.", 'start': 695.737, 'duration': 4.642}, {'end': 702.3, 'text': 'Let me just run it real quick, see if we hit error.', 'start': 700.579, 'duration': 1.721}, {'end': 702.96, 'text': 'Yeah, okay, it is.', 'start': 702.46, 'duration': 0.5}, {'end': 707.942, 'text': 'Okay, so it is runnable at this stage, but we have a couple of issues.', 'start': 703.44, 'duration': 4.502}, {'end': 719.166, 'text': 'The first thing is, anytime you send off a coroutine to run, You want to make sure you wait for the coroutine to finish,', 'start': 708.582, 'duration': 10.584}, {'end': 724.427, 'text': "especially if you're going to start a new loop or if you're going to end your code.", 'start': 719.166, 'duration': 5.261}, {'end': 730.768, 'text': "So if you're just if you're writing a script that happens to use asyncio, if you happen to need to do that,", 'start': 724.787, 'duration': 5.981}, {'end': 738.229, 'text': "you want to make sure you've waited for the results before you end the script, or but again in a loop, especially if you don't wait.", 'start': 730.768, 'duration': 7.461}, {'end': 738.829, 'text': "you're just going to.", 'start': 738.229, 'duration': 0.6}], 'summary': 'Code is runnable, but has issues with coroutine handling and waiting for results.', 'duration': 43.092, 'max_score': 695.737, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/BI0asZuqFXM/pics/BI0asZuqFXM695737.jpg'}, {'end': 1142.916, 'src': 'heatmap', 'start': 1114.663, 'weight': 1, 'content': [{'end': 1118.632, 'text': 'If I modular, Oh my gosh.', 'start': 1114.663, 'duration': 3.969}, {'end': 1119.812, 'text': 'Okay Okay.', 'start': 1118.832, 'duration': 0.98}, {'end': 1121.733, 'text': "Woo That's why.", 'start': 1120.432, 'duration': 1.301}, {'end': 1125.033, 'text': 'Okay Anyways.', 'start': 1121.953, 'duration': 3.08}, {'end': 1128.954, 'text': "Yeah So, so I bet that's always true.", 'start': 1126.053, 'duration': 2.901}, {'end': 1131.334, 'text': "We're going to start again.", 'start': 1128.974, 'duration': 2.36}, {'end': 1133.815, 'text': 'Cool All right.', 'start': 1131.654, 'duration': 2.161}, {'end': 1138.616, 'text': 'So what we did wrong or what I did wrong here is we never had the double equal zero.', 'start': 1133.995, 'duration': 4.621}, {'end': 1142.916, 'text': "So basically it was just, what's the remainder of I divided by 500,000.", 'start': 1138.676, 'duration': 4.24}], 'summary': 'Discussion about identifying and correcting a mistake in a code, related to the condition of double equal to zero, in the context of dividing by 500,000.', 'duration': 28.253, 'max_score': 1114.663, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/BI0asZuqFXM/pics/BI0asZuqFXM1114663.jpg'}], 'start': 639.645, 'title': 'Asynchronous programming', 'summary': "Discusses creating asynchronous loops, using 'loop.create_task' to run three functions synchronously, and the importance of awaiting coroutines in asynchronous programming. it also covers the use of asyncio sleep to create pauses and the impact of sleep duration on program performance.", 'chapters': [{'end': 695.617, 'start': 639.645, 'title': 'Asynchronous loop creation', 'summary': "Discusses creating an asynchronous loop, where functions are added to the loop using 'loop.create_task' to run synchronously, achieving the goal of running three functions.", 'duration': 55.972, 'highlights': ["Creating an asynchronous loop using 'loop.create_task' to run three functions synchronously.", 'Inserting functions into the loop to run them in an asynchronous manner.', 'Running main coroutine and creating a task in the loop to execute three functions.']}, {'end': 1271.383, 'start': 695.737, 'title': 'Asynchronous programming and await', 'summary': 'Discusses the importance of awaiting coroutines in asynchronous programming, using asyncio sleep to create pauses, and the impact of sleep duration on program performance.', 'duration': 575.646, 'highlights': ['The chapter discusses the importance of awaiting coroutines in asynchronous programming It is crucial to wait for coroutines to finish, especially before starting a new loop or ending the code.', 'Using asyncio sleep to create pauses Demonstrates the use of asyncio sleep to introduce pauses in the program execution, impacting the order and timing of coroutine execution.', "The impact of sleep duration on program performance The duration of asyncio sleep affects the program's performance, with even a very small sleep incurring a slight penalty in concurrent execution."]}], 'duration': 631.738, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/BI0asZuqFXM/pics/BI0asZuqFXM639645.jpg', 'highlights': ["Creating an asynchronous loop using 'loop.create_task' to run three functions synchronously.", 'The chapter discusses the importance of awaiting coroutines in asynchronous programming.', 'Using asyncio sleep to create pauses Demonstrates the use of asyncio sleep to introduce pauses in the program execution, impacting the order and timing of coroutine execution.']}, {'end': 1715.536, 'segs': [{'end': 1364.525, 'src': 'embed', 'start': 1305.189, 'weight': 0, 'content': [{'end': 1308.433, 'text': "Now, I'll just return them first and then we'll talk.", 'start': 1305.189, 'duration': 3.244}, {'end': 1320.165, 'text': "So then once you've returned these, basically when you run this right here, this does return things and it returns these result objects.", 'start': 1309.394, 'duration': 10.771}, {'end': 1325.771, 'text': 'So we could say d1, d2, d3 equals loop.runUntilComplete.', 'start': 1320.686, 'duration': 5.085}, {'end': 1329.916, 'text': 'Then what we have are the result objects.', 'start': 1326.573, 'duration': 3.343}, {'end': 1331.057, 'text': 'They are not results.', 'start': 1329.976, 'duration': 1.081}, {'end': 1334.459, 'text': "So you actually need to say, let's say we just want to print them out.", 'start': 1331.557, 'duration': 2.902}, {'end': 1337.162, 'text': "We'll just print d1.results.", 'start': 1334.579, 'duration': 2.583}, {'end': 1342.566, 'text': "So we'll just run that result method basically on that and boom.", 'start': 1337.902, 'duration': 4.664}, {'end': 1347.39, 'text': 'So 4d1, which was here, all the numbers divisible by 34,113 in that range, here they are.', 'start': 1343.086, 'duration': 4.304}, {'end': 1348.511, 'text': "So that's how you can get your results.", 'start': 1347.41, 'duration': 1.101}, {'end': 1364.525, 'text': 'so next, what i want to do is talk about uh, what happens when we make mistakes?', 'start': 1357.139, 'duration': 7.386}], 'summary': 'Returning result objects, printing and running result method, obtaining numbers divisible by 34,113.', 'duration': 59.336, 'max_score': 1305.189, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/BI0asZuqFXM/pics/BI0asZuqFXM1305189.jpg'}, {'end': 1485.414, 'src': 'embed', 'start': 1461.201, 'weight': 5, 'content': [{'end': 1471.628, 'text': 'Well, what has happened is we started all these coroutines, but we can zoom through our script before we can get the return of the coroutine,', 'start': 1461.201, 'duration': 10.427}, {'end': 1473.99, 'text': "because we just dispatched those out and they're off in the.", 'start': 1471.628, 'duration': 2.362}, {'end': 1479.748, 'text': "they're just gone now and and uh, and so at this point.", 'start': 1474.763, 'duration': 4.985}, {'end': 1485.414, 'text': "so i guess, if you don't close your loop, so at least here it would seem to suggest.", 'start': 1479.748, 'duration': 5.666}], 'summary': 'Coroutines started but not returned, causing script to zoom through.', 'duration': 24.213, 'max_score': 1461.201, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/BI0asZuqFXM/pics/BI0asZuqFXM1461201.jpg'}, {'end': 1579.685, 'src': 'embed', 'start': 1552.983, 'weight': 4, 'content': [{'end': 1558.184, 'text': 'OK, so the other major mistake, I think, is just getting used to the syntax.', 'start': 1552.983, 'duration': 5.201}, {'end': 1564.725, 'text': "And if you start writing def main, it's like what if we, if we just remove async from in front of define main?", 'start': 1558.884, 'duration': 5.841}, {'end': 1568.997, 'text': 'um, very suddenly you can already see sublime is telling me um,', 'start': 1565.794, 'duration': 3.203}, {'end': 1579.685, 'text': "but if we go to run this boom suddenly we have a syntax error right and and at least if, if you're brand new to writing, uh, working with async io,", 'start': 1568.997, 'duration': 10.688}], 'summary': "Major mistake: syntax error when removing 'async' from 'define main'.", 'duration': 26.702, 'max_score': 1552.983, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/BI0asZuqFXM/pics/BI0asZuqFXM1552983.jpg'}, {'end': 1649.235, 'src': 'embed', 'start': 1619.668, 'weight': 6, 'content': [{'end': 1623.849, 'text': 'Maybe do something a little more project-based than just real basic like this.', 'start': 1619.668, 'duration': 4.181}, {'end': 1626.509, 'text': 'This is not really super practical.', 'start': 1623.969, 'duration': 2.54}, {'end': 1637.469, 'text': "But basically the crux of the situation is it's all about async await and some sort of some sort of way to suspend things again.", 'start': 1627.63, 'duration': 9.839}, {'end': 1641.171, 'text': "like i said before, i think it's aio http.", 'start': 1637.469, 'duration': 3.702}, {'end': 1649.235, 'text': "i need to open up a search bar, aio http, which i'm pretty sure is third party.", 'start': 1641.171, 'duration': 8.064}], 'summary': 'The transcript discusses the need for a project-based approach, focusing on async await and aio http for a search bar.', 'duration': 29.567, 'max_score': 1619.668, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/BI0asZuqFXM/pics/BI0asZuqFXM1619668.jpg'}, {'end': 1701.493, 'src': 'embed', 'start': 1674.778, 'weight': 2, 'content': [{'end': 1680.482, 'text': "because I think it's mostly just so you can have the asynchronous client personally like,", 'start': 1674.778, 'duration': 5.704}, {'end': 1684.568, 'text': "because otherwise you'd probably have or at least a session and stuff like that.", 'start': 1680.482, 'duration': 4.086}, {'end': 1690.129, 'text': 'So working that out and having everything be really truly asynchronous would be a lot of work.', 'start': 1684.648, 'duration': 5.481}, {'end': 1693.57, 'text': 'So anyways, yeah, check that out.', 'start': 1690.209, 'duration': 3.361}, {'end': 1696.331, 'text': "So anyway, I think that's all for now.", 'start': 1694.131, 'duration': 2.2}, {'end': 1701.493, 'text': 'If you guys have questions, comments, concerns, whatever, feel free to leave them below.', 'start': 1696.591, 'duration': 4.902}], 'summary': 'Discussing challenges of achieving true asynchronous client and session management.', 'duration': 26.715, 'max_score': 1674.778, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/BI0asZuqFXM/pics/BI0asZuqFXM1674778.jpg'}], 'start': 1271.663, 'title': 'Python functions and returning values', 'summary': 'Covers retrieving values from functions and handling errors in python asynchronous programming, with an emphasis on returning values and error handling. it also discusses common mistakes in asynchronous programming, including not awaiting returns, syntax errors, and the importance of closing the loop, with a focus on async await and aio http for asynchronous web tasks.', 'chapters': [{'end': 1364.525, 'start': 1271.663, 'title': 'Python functions and returning values', 'summary': 'Covers retrieving values from functions and handling errors in python asynchronous programming, with an emphasis on returning values and error handling.', 'duration': 92.862, 'highlights': ['Returning values from functions, such as divs one, divs two, and divs three, is crucial for obtaining result objects and effectively handling asynchronous programming.', 'The process of printing and obtaining the result method, such as d1.results, is demonstrated as a means of retrieving specific results from the functions.', 'Emphasis on the need to address mistakes and error handling within the context of Python asynchronous programming.']}, {'end': 1715.536, 'start': 1364.525, 'title': 'Common mistakes in asynchronous programming', 'summary': 'Discusses common mistakes in asynchronous programming, including not awaiting returns, syntax errors, and the importance of closing the loop, with a focus on async await and aio http for asynchronous web tasks.', 'duration': 351.011, 'highlights': ['Not awaiting returns is a common mistake in asynchronous programming, as it can lead to asynchronous execution without waiting for the results, causing issues in completing tasks. Not applicable', "Syntax errors, such as forgetting to include 'async' before defining the main function, are highlighted as another common mistake in async IO, leading to syntax errors when running the code. Not applicable", 'The importance of closing the loop is emphasized, as failure to do so can result in tasks being dispatched without waiting for the coroutine to return, leading to potential warnings or errors. Not applicable', 'The significance of AIO HTTP for asynchronous web tasks is mentioned, particularly for asynchronous client usage, making it a valuable tool for web-related asynchronous operations. Not applicable']}], 'duration': 443.873, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/BI0asZuqFXM/pics/BI0asZuqFXM1271663.jpg', 'highlights': ['Returning values from functions is crucial for obtaining result objects in asynchronous programming.', 'Demonstrating the process of printing and obtaining the result method, such as d1.results, from functions.', 'Emphasis on addressing mistakes and error handling in Python asynchronous programming.', 'Not awaiting returns is a common mistake in asynchronous programming, leading to issues in completing tasks.', "Syntax errors, such as forgetting to include 'async' before defining the main function, are highlighted as common mistakes in async IO.", 'Emphasizing the importance of closing the loop to avoid potential warnings or errors in asynchronous programming.', 'AIO HTTP is mentioned as a valuable tool for web-related asynchronous operations.']}], 'highlights': ["The significance of asyncio in web development is highlighted by demonstrating how synchronous loading can lead to the entire webpage hanging when waiting for a non-responsive server, while asynchronous loading allows other elements to load concurrently, mitigating the impact of a non-responsive server on the webpage's performance.", 'The concept of concurrency in programming is clarified by comparing it to handling multiple tasks at once, such as tying a shoe and running, to illustrate the ability to perform multiple tasks concurrently.', 'Asynchronous programming in Python is demonstrated through real-life examples, such as tying a shoe while on a jog and loading web elements concurrently, emphasizing the importance of handling tasks concurrently without necessarily doing them in parallel.', 'The tutorial emphasizes the flexibility of the function, allowing users to modify it for various purposes such as performing Fibonacci calculations.', 'The function demonstrated in the tutorial involves finding numbers within a given range and performing division operations, with the ability to customize the function for different purposes.', 'The main function is illustrated with specific inputs and outputs, showcasing the practical application of the coroutine in Python for concurrency.', 'The tutorial begins with a discussion on converting a basic function into a coroutine, with a reference to the use of goroutines in Go for concurrency.', 'The need for asynchronous execution is highlighted by the potential time savings, where tasks could run concurrently instead of sequentially, reducing wait times.', 'The script runs synchronously, taking about 0.3 seconds to iterate through 508,000 instances in the order they are called.', 'Introduction to AIO HTTP is discussed, with a mention of the complexity of the package and the need for simpler documentation for beginners.', 'The drawbacks of using threading or multiprocessing for async execution are mentioned due to the additional complexities involved.', "The main conversion process involves using 'async def' to notify Python that a function is a coroutine and importing 'asyncio' for utilizing helper functions, leading to the establishment of the main event loop.", 'The importance of establishing the main event loop and adding tasks to instruct the loop on how to run is highlighted for managing asynchronous operations.', "The significance of initializing the event loop using 'asyncio.get_event_loop' is noted to run the main coroutine until it's completed.", 'The asyncio package usage involves functions like run until complete, run forever, and loop close, with the need for proper event loop management and exception handling.', 'It is important to always close off the event loop using loop.close, and handle exceptions properly to avoid issues during asynchronous operations.', "The chapter emphasizes that async IO is not the sole method for concurrency in Python, as it provides multiple options including 'yield from', 'go' coroutine, and decorators for concurrency.", "Creating an asynchronous loop using 'loop.create_task' to run three functions synchronously.", 'The chapter discusses the importance of awaiting coroutines in asynchronous programming.', 'Using asyncio sleep to create pauses Demonstrates the use of asyncio sleep to introduce pauses in the program execution, impacting the order and timing of coroutine execution.', 'Returning values from functions is crucial for obtaining result objects in asynchronous programming.', 'Demonstrating the process of printing and obtaining the result method, such as d1.results, from functions.', 'Emphasis on addressing mistakes and error handling in Python asynchronous programming.', 'Not awaiting returns is a common mistake in asynchronous programming, leading to issues in completing tasks.', "Syntax errors, such as forgetting to include 'async' before defining the main function, are highlighted as common mistakes in async IO.", 'Emphasizing the importance of closing the loop to avoid potential warnings or errors in asynchronous programming.', 'AIO HTTP is mentioned as a valuable tool for web-related asynchronous operations.']}