Asyncio is a Python library that enables concurrent programming by allowing multiple tasks to run simultaneously without blocking the entire program. The await keyword pauses the current coroutine and yields control back to the event loop until the awaited task completes, enabling efficient multitasking. Key concepts include creating async functions with 'async def', using asyncio.create_task() to schedule coroutines in the background, implementing retry systems with try-except blocks, managing timeouts with asyncio.wait_for(), and handling task cancellation with asyncio.CancelledError.
Deep Dive
Prerequisite Knowledge
- No data available.
Where to go next
- No data available.
Deep Dive
Asyncio and async/await | AI Engineering for 365 Days | (Day 9/365)Added:
Heat.
Heat.
Fire.
Oh, alert. Hold up, guys. All right, we're live. We're live. Let me go to my main camera.
Oh, actually, no wonder it felt a little awkward cuz I usually go with my testing. That's live. And as you guys can tell by that thumbnail, today I'm going to working on Chenille. Wait slash I think it was I forgot what was the topic again. Asentio, async and awake.
It is currently the day nine for my AI engineering for 365 days series where last stream I was working on 30 instructional based questions. Although I did stop at the first nine questions.
Although today I'm going to working on the rest, let's say 21 questions. So let's rush the process and move on to my gameplay screen. There we go. Okay. And now here, let me go ahead and say something like the same live exclamation. And yeah, guys, this is a brand new chat because I'm trying to use new chats every single stream now, unless I really think that the previous chat did not really consume as many tokens. Speak. Excuse me, guys. Speaking of which, hey there.
There we go. Okay, so let's quit all the extra stuff for two minutes. And I'm going to be saving a lot of time here.
So, question nine. You've already crushed questions one through eight.
Okay, for the question nine, retry system. Write an async program that simulates a retry system. If a task fails, it keeps trying until it doesn't succeed. Requirements: Create an async function that fetches data. Create a async function. Fetch data that takes a parameter attempt.
Waits one second. If attempt is less than three, prints attempts of my attempt fails and raises an exception.
If attempt is three more than prints data fed successfully and returns creates a async function fetch with retry that starts attempt one, keeps calling fetch data in a loop, catches the exception and increments attempt stops when it succeeds. Attempt one failed, attempt two failed. Data fetched successfully. I see. Okay. And yeah, as usual, I'm going to go ahead and get this in the order window. Speaking of which, my mouse is too fast. Oh, guys, I'm trying to see how this DPI thing works. So, I basically have a DPI button in my mouse that is set to three different settings. Huh, interesting.
Okay, speaking of which, I am I am going to open my Visual Studio as well. Since I am uh what we call it, it planning to play Valent on my streams for my gaming channel. I'm going to just go ahead and get used to high sensitivity because I am a high sensitivity player. Let's let me go all the way here, get the instructions in another window just so I can read them while I work on my questions. There we go. Now to work on my questions since my topic is based on the asyncos I'm going to go ahead and import my asycio my async neo and then I'm going to go ahead and create an uh create an async function called fetch data that takes a parameter of a temp. So I'm going to go ahead and create a async says a function which is also known as a co redeem function that is going to be called something like fetch underscore data.
Okay, that requires attempt as a parameter. Okay. And then uh waits 1 second. Waits 1 second if attempt is less than three prints attempt failed and raises an exception. So, we're going to go with something like await. And await is a keyword that can only work inside of a um co routine function.
Therefore, I'm going to go with await asenteneo sleep for one second. And then once we're done with that, if attempt is less than three, print attempt failed and raises an exception. I'm going to add an if statement that says if my attempt is less than three. Okay, if the attempt is less than three, I'm going to do something. I'm going to go ahead and print.
Let's say something like attempt failed.
Hold on, guys. This is so annoying that thing that just pops up. Let's go with attempt number. My attempts is variable failed. Okay. Okay. And then we're going to go with dot dot dot. And since I am actually trying to add a variable inside of a print statement, I'm going to go ahead and change this to like an string.
Okay. And raises an exception. Okay.
Let's go with something like raise exception.
I won't specify what exception, but I'm going to say something like something went wrong. Okay, perfect. Next up, once we're done with that, if attempt is more than three, prints data fed successfully and returns. Okay, let's go with something like else if.
If it's not less than three, of course, it's going to be greater than three. I'm going to go with else.
Print an F string that says something like, well, not an F string. I'm just going to go with data fetched successfully.
There we go. with an exclamation and returns.
Okay, so we're going to go ahead and return. Next up, creates an async function. Okay, call fetch with retry that starts attempt at one, keeps calling fetch data in a loop. Catches the exception and increments attempt, stops when it succeeds. Okay, hint strikes have works perfectly inside async functions. A while true loop with a break on success works cleanly here.
Raise exception manually triggers a failure. Okay, for the third step, I guess let's go ahead and create another async function. So I'm going to create another C routine function called uh fetch with retry.
Let's go with something like fetch with retry.
Okay, which is let's see that starts at attempt one. Okay, it does not require any parameter. Bro, can you do it full screen um watching here? Actually, if you guys are in my vertical stream, make sure to move on to my horizontal stream.
That's where I do display my window in landscape mode. Many of you guys don't fully know that if you guys watch my vertical streams. Let me check. Oh, you are in the vertical stream. Okay, so move on to the horizontal stream that is on my channel. Like, let me show it to you guys real quick. So, let me just go ahead and open my channel real quick.
Then let's go there. I'm going to grab plot here just so I can uh show my window.
There we go. Okay. So, basically if you guys are in the vertical stream, you guys can't fully see this video and PC feels kind of small. There we go. So, I have two different streams in my channel if you guys do click my channel. One is the vertical stream where you guys see it in portrait mode as a YouTube short.
The other one is in the as a horizontal stream which you guys can see in a landscape mode that is like a regular long form video. So if you guys do click this, this is my entire video right now or my entire uh display right now. Video in PC feels kind of small. I see. Okay, that's said. Let's let's read the next instructions. Create an async function fetch with retry that starts at attempt one.
That starts at attempt one. keeps calling fetch data in a loop. Isn't fetch Oh, okay. And returns. So, I think I should return my fetch data, right? No, I think I should return my attempt.
There we go. So, I returned my attempt number.
I don't know. Maybe if I go back there.
There we go. Okay. I think this returned would be the best. I'm going to go ahead and have an await variable.
I meant I mean attempt. And guys, I'm not warmed up just yet. Let's set.
Yellow down. Let's go. Okay, let's see.
So, create an async function with fetch retry that starts at attempt one. Create an async function fetch with retry that starts at attempt one. Okay, so my attempt is going to be equal to one.
Let's go with something like attempt equals to one and then uh keeps calling fetch data in a loop. So let's go with a while loop. So we're going to go with something like while.
Here's the thing. Should it be while true? Okay, that is a pretty nice thing.
So while true creates a fetch stuff, keeps calling fetch data in a Oh, I see.
I see I see I see I see I see. We're going to call our function here while true. Call our fetch data as this function that requires an attempt function.
Okay, I see. And keeps calling fetch data in a loop that catches the exception and increments attempt stops when it succeeds. Okay, so in a while loop in a while loop, let's go ahead and try. So I'm going to go ahead and try my fetch data. Whoops. What up, guys?
Okay, so we're going to go ahead and try and I will be accepting an exception as error. Okay, so I'm going to accept exception as error and then let's see.
Okay, stops when it succeeds. Stops when it succeeds.
So, we're going to try that and then let's see. So, I'm going to say okay, keeps calling. We're going to say attempt one fails, attempt two fails.
Okay, we call our function except exception as error.
Okay, so keeps calling fetch data and it loop catches the exception and increments attempt. So if I catch an exception, I got to increment my attempt. So let's go with something like attempt plus equals to 1 stops when it succeeds.
So, it stops when it succeeds.
I think it should um I'm going to go here.
Else break. There we go. You know, I could just try it. So, if there if no exception happens, I could break easily.
Okay, I guess let's try running it and then expected output blah blah blah. All right, let's let's run the program real quick now. So I'm going to go ahead and firstly this is just going to be a regular return or should it be return attempt that is going to be my attempt okay you know what let's try it I'm going to go ahead and create a main function let's go with something like uh define main or well let's go with an async function I do want to use the await keyword okay so we're creating an a corine function called main that does not require any parameter Excuse me guys. Although it does require my fetch data.
Okay, it does require my fetch data as this function and it requires my fetch with retries this function. You know what? I think fetch with retry is the only function that I might need here.
And then we're going to go ahead. This is going to be a wait.
Okay. Okay. And then let's just go ahead and go with asentino run. I want to run my main function. Let's hit control S control. Oh wow, we run into a bunch of errors. Maybe there is no wait here.
Hold on.
Wow. Why is there a bunch of error fetch with retry missing one positional argument? Oh, I forgot I had an attempt.
Let's go with one.
Okay, so runtime warning enable trace object allocation. Okay, we need an await. I was right there.
Okay, so wait, we still get that stuff.
Did I hit control S?
Crl S control.
Okay, runtime corine fetch was never awaited or uh quarantine of fetch was never awaited. So, we await.leep.
Oh, wait, wait, wait, wait, wait, wait, wait. My bad. My bad. My bad, guys. Hold on. My bad. I forgot one thing. We're going to go with await as gather. I want to go ahead and gather my fetch with retry this function that requires a parameter of one. Now, if I run the program, one time error. Why did I still get an error guys? Hold on. This is fetch with retry and then blah blah blah. Those are three. That is three. That requires attempt and that requires attempt.
You know what? You know what? You know what? I think I need to call my uh freaking fetch with reach uh my fetch function um my fetch datas function as well. Let's paste this.
Okay, let's go with fetch data. I'm going to copy that. I'm going to go with Ctrl + Z and I'm going to go ahead and paste this. Okay. Um, I may return a value.
This is going to be 1 second.
Now, let's go with control s exception. Something went wrong in line 8. I mean, I know what's going wrong here. I know what's going on here.
You know what? I guess let's go with controller control within fetch with a retry. You call fetch. I think you got the await.
I think you forgot the await. I did add the await though. Like there is no asenteneo functions here.
What exactly are you working on? I'm basically working on a few instructional based questions for asentino await and async functions. That said, I'm just getting warmed up right now. This is question n where I left. Let me say something like sensei. I messed up.
>> Okay. And then let's send it. There we go.
Okay. And then let's see that. Let's go all the way up here. All right guys, we're still warming up here. Last stream. I did work on the first nine questions. This this stream my head is not really on the programming base right now. No await. Oh, so we were missing a wait bug too in your main function.
Fetch with retry already calls us stuff.
All right. All right.
fetched. So it's ba okay it was basically I oh it's an asentio function I mean it's a corine function of course it needs an await and then fec so it already calls the stuff so we don't really need gather so it was basically typos that's all wow it was typos what the hell guys this is the worst thing here like it's it shows all Massive bucks. Told you. So, dude guys, I actually, you know what? I worked so much with this live stream. I did know that Corine Functions always leads in a weight. Oh god, that was kind of awful. But yeah, I guess I won't make that mistake again. There we go. Let's go ahead and paste it and say uh I see someone from by chat told me that I can't believe that I forgot that corine functions uh needed and wait that said can I get the next question now?
Okay guys, this is starting to get interesting because there are two kinds of uh there are two two ways that I actually make mistakes. First way is when I make mistakes and I don't really know the topic. That's the worst kind of mistake. The second mistake is when I make a mistake but I do know the topic.
That is the fun kind of mistakes. Why does async and asyncer what what is async and asyncer used for? Basically uh let's think about it like when a regular function runs or let's give an AI's example only. For example, pretend that I'm an or not an AI, let's give a waiter's example. Pretend that I'm a waiter right now. I'm taking an order for a customer. That customer gives me an order. I go all the way back to the kitchen and give those people the order and wait for them to give me uh the meal that the let's say um the customer ordered. Once the meal is done, I grab that meal and I give it to the customer.
Then I move on to the next customer, ask for the order again, go and repeat the same process. It gets a little tedious.
The thing that as async and uh async actually does is that I'm going to be getting or requesting an order from my customer. As soon as I get that order, I'm going to give it uh to the people in the kitchen. And then while they're working on that order, I'm going to move on to the other customer, get the content from them, give it back to the kitchen, go back and all that stuff.
Once my first order is complete, I'm going to grab that order and give it to the customer. If that makes any sense.
That is just a more effective way to um that's just more effective in general rather than waiting to get a response and then moving on to the next question because AI is they request many or should I say separate uh let's say databases at the same time to like get a kind of answer. I'm not that good with it. This is just what this does. That said, once you fix the typo, fch. Fine.
Feet t.
Okay. I think I think my typos are f there.
There we go. And guys, I got to like work on my um freaking explaining these topics. I feel like I explain it way too fast.
Done.
Okay. And I said that I got to like move on to the next part.
Let's see. Let's see. Almost. Oh my gosh.
Can we move on to the next question? I want to be done with all three. I will be more careful with my typos.
from the next chat. Actually, from the next question. There we go. Guys, this is one annoying thing about plot. It's so picky for stuff. Funny thing is, I literally had typos while literally saying that I will be careful or mindful about me typing. That said, question number 10. Async timeout system. I've got to write an async program that cancels a task if it takes too long.
requirements. Create an async function, also called a C routine function, called long task, that prints task started, waits 5 seconds, then prints task finished, creates an async function called main that tries to run long task with 3 seconds. Time out using async.wait_4.
Okay, I need to know what does the weight really do? You should use async asynco to call an actual API. For example, try to talk to sensei with his API from your code. Actually, yeah, I think my road map does really have that stuff as well. But firstly, I'm just working on the basics and then I will be working on more projects and I think the fifth or sixth topic on my road map is working with LLM models. Before that, I got to learn Git and GitHub as well.
That said, if the task times out, catch the exception.
Alrighty. Wait, let me say I have uh not worked with the uh weight_4 method and also and also the timeout error. Can you explain them to me first?
Then we can work on the question by we actually meant me. That's it. Let's send it. Okay, now let's see.
Okay, good call. Never skip the teaching. That's exactly the right instinct. Let's break it down. Aso wait forces method sometime takes too long.
So sometimes a task takes too long in real apps. You cannot wait forever. You need to cut it off. That's what waiters_4 does. Syntax await asore for my cor routine function and my time out says quark in seconds.
It runs the co routine but if it takes longer than n seconds, it cancels it automatically.
Await asenteneal.waiters Wait_4 long task time out three. If a long task takes more than 3 seconds, cancelled. By the way, it's not pronounced asentio.
It's essential, which is short for asynchron asynchronous meaning doing more than one thing at once. Input output. Oh, I see. Hold on.
Let's go with something like English to Japanese. I just use the English for Japanese basically for a regular translator. Let me sort of kind of copy this stuff here.
Yeah, I usually ask the pronunciations like I try to get my pronunciation here but they might have it wrong.
>> Asio.
>> Oh, asio. There we go. Or essentio.
And then that is asynchronous.
>> Essentio.
>> Essentio. It's so hard to get that name in check. That said, we go with something like essential wait for long task time out 3 seconds. essential timeout error. When wait for cancels a task, it raises essential timeout error.
You catch it exactly like any other exception. Try await essentio wait for core routine function and a quark except essentio timeout error prints task timed out putting it together define main yada yada I see now the concept is straightforward wait wraps your co- routine sets timer and blows up if it's too slow time out is your signal that happened now okay Guess let's write the question 10. I'm going to go ahead and get it in the other window just so I can read the question as a reference.
Okay, so question 10. I'm going to delete this again. We're going to go ahead and import my essential since I am going to be working with it.
And then I'm going to go ahead and create a coarine function called log task that does not require any parameter. However, I will be printing something. I'm going to be requiring a print statement that says task started dot dot dot. Okay. And then I need to wait for 5 seconds. So I'm going to go with something like await my essential.
Okay. Essentio.
Is going to be 5 seconds.
And then create an async function. So we're going to go ahead and uh create another async function.
Okay. Called something like main is also a core function which is going to go ahead and u tries to run the long task with a 3 seconds timeout. Okay. So I guess I'm going to go ahead and try my await my essential dot wait for. Okay. So when calling my function, I want to call my long task routine.
Okay. And I want to wait for let's say 3 seconds. If the function was longer than 3 seconds, I want to go ahead and accept a time out error.
There we go. If it was longer than 3 seconds, I want to accept a timeout error. Okay, we wait for that time.
Waits for five seconds and then prints task finished. Oh, I forgot to print task finished.
There we go.
Okay. And now we have a timer error that says something like Okay, that waits for this thing.
Task timed out. Okay. So, we're going to print something like task timed out. There we go.
Okay, that is the expected output.
There. Okay, now let's go ahead and run our function. I'm going to go with essentio.run.
I want to go ahead and run my main function.
Syntax error. Invalid syntax. No colons.
Oh, guys, I'm such an idiot. Task started.
Task timed out because it was a 3 seconds. What if I had this to be 6 seconds? This is going to say task finished in a whopping 6 seconds.
Nice.
You know what? I'm starting to see what this actually means. I'm starting to understand asio including generators, context managers and um decorators.
Yeah, let's paste it and say done.
Let's move on.
All right. Chop chop chop chop guys.
Chop chop and let me know how fast can you guys actually answer these questions. Well, it's not a real world so you get the incorrect uh pronunciation in Google.
It's async io and IO is pronounced separately.
Well, no matter pronouncing does not matter. Code does. It actually does make sense. So, async io is that IO is pronounced separately. So, async io, we import async io.
Is it actually async io? Wait, one quick note before question 11. your wrote time out and since you're on Python 13.12 it actually works because Python made them the same in 13.11 plus but get into the habit of writing a sync io time error because it's because in older code base bases and on other machines it will break be explicit always okay so we got to go with async io time moder question 11 let's see if you how asking you guys actually answer these mallet solve this question running task concurrency with hold up with a sync io.create task new concept incoming read before your code async io.create Create task schedules a co routine to run immediately in the background without awaiting on spot. Unlike gather, you create the tasks first then awaits them later giving you more control. Task equal.
All right. What does the create task do?
Now write a requirements create an async or function called brew coffee that waits 3 seconds and prints coffee ready.
Well, I learned this way back, so I already know all this, but it's fun to watch someone else run. Guys, it actually sounds kind of cool. That said, creates an async function called toast bread that waits 2 seconds and prints toast ready. In main function, use async io.create task for both then await both tasks. Total time should be 3 seconds and not 5 seconds. Hence, create both. Okay, firstly, what does the create underscore task do? Okay, firstly before I work on the question, what does the create_taskes method do? Question mark. Okay, let me see what the method does real quick. I'm going to go ahead and send that real quick.
Good. You're asking for coding a sync io.create task. Remember, gather it runs corine simultaneously. It does, but it starts and awaits them all at once. You don't get them individually yet because it's asynchronous. Not uh should I I forgot what was the other word where it waits for one task to be complete and then goes to the second task and the third task. Dude, I just got two uns skippable ads. YouTube is so annoying, guys. That's actually annoying. Like, I hate it when they actually give those things.
That said, and gives you back a task object you can use later. Task equals to async io.create task some corine. So, that is a corine function.
That task is already running the moment you create it. You're not waiting. It's just going in the background while your code keeps moving. Gather versus create.
Await async io. Gather task one task two create task start now. Await later when you choose task one.re t test two.create task await task one await task two. Now wait for task one. Now wait for task two. Why does this matter? with create task. You can do other things between creating and awaiting long download. I'm doing other things.
Oh, okay. Now, question 11. Oh god, guys, this is going to be a bit complex.
Okay, let's see. Let's see. I hope that I don't mess this stuff up.
So, question 11's references there. I'm firstly going to go ahead and let's say import my async ios this function because I'm going to use it.
Okay, concept incoming. Async io.create schedules a corine to run immediately in the background without awaiting it on the spot.
Requirements create an async function.
So, we're going to go ahead and create an async function called actually a C routine function called brew coffee that waits 3 seconds.
Assentios sleep is going to be something like 3 seconds.
I mean async io. Is going to be 3 seconds.
Um, what happens if I go with lower case? Does that work?
That's much better actually. Okay, so I wait for 3 seconds and then we're going to go ahead and print something like coffee ready.
There we go. Okay, let's go with something like ready.
Okay, perfect. And then next up, create an async function called toast bread. So I'm going to go ahead and let's say tree well. And then I'm going to go ahead and create another async function called toast bread. Let's see that requires I mean that waits for two seconds. So, async io sleep, let's go with something like 2 seconds. And then it prints something like toast ready.
There we go. Okay. And then in our main function, so let's create another asyn async corine function called main.
I think I spelled this wrong. There we go. Now, this is where the this is where the new topic starts. use async io.create create task create tasks is method and yeah I know I got to add a weight here since I'm working with an async iOS's function uh for both then wait for both then wait both tasks total time should be 3 seconds not 5 seconds um okay so we're going going to go with something like I'm going to go ahead and brew my coffee and then let's go ahead and toast my bread and then uh Ctrl S. Wait, actually I'm going to go with Assentio.
I want to run my main function now.
Three. Oh, we got an error. That's incorrect.
Should I just go with um one enable? Oh, why? Cory sleep was never awaited. I did await. Oh. Oh. Oh. Oh. My bad. My bad. My bad. My bad. Hold up, guys. My bad. My bad. My bad. My bad. My bad. Hold up, guys. There we go. Rookie mistake.
And then let's go with toast bread.
You don't await create task. That's the whole point. You don't await create.
You don't await create task.
I thought all as Neo methods must be awakened.
Okay. Task one create await task one then await task two. Create both tasks before awaiting either one. So should it be something like uh await task one which is going to be equal to brew coffee and then we're going to go with await task two which is going to be equal to toast bread and then I'm going to go ahead and let's say call my um variables task one and then task Do you awake that task? You await that task. Create a task returns a task.
Create task returns Oh, wait. Create task returns a task.
You await that task.
Wait, what was the syntax?
Oh, task one equals to Hold up, guys. Task one equals to There we go. Okay, so task one equals toio.create task. This is going to be my brew coffee.
Whoops.
Why is my mouse sensitivity so freaking high?
Okay, and then we're going to go with test two.
There we go. Let's go with task two equals to essentio dot oh this is in that case this is like um the pickle and unpickle module for serial for like serialization when you use the dump method in a file you dump the stuff in the file you don't really need to catch it but then when you try to let's say load it you got to save that in a variable I think this is the same as that and I'm going to add a close parenthesis how did I add all those quotes. Now we hit control and still waiting.
That was more than 5 seconds, right?
Await task one. Await task two.
There. Now if I run the program, toast ready. Coffee ready.
Oh, wow. Okay, this was this was a really fun question actually. Hold on, guys. Let me just go up here. I'm going to go ahead and grab this. Okay, let's paste this and say um it works although uh I got helped by my chat basically through the entire program. So for question, excuse me guys, for question 12, can I get a similar question just with a different variation question mark? There we go.
Let's go ahead and send it real quick.
Okay, because I think I got help, but I understand it now. You didn't await the tasks. That actually does make sense.
That said, async code is fun, but it's the root of 95% of the bugs, guys. That is actually really fun, though. Okay, question 11. We do create an async function called boil water that waits for 4 seconds. Print water boiled. Create an async function for chop vegetables that waits for two seconds then prints vegetables chopped.
Create an async function for fried for fry eggs. waits three seconds then prints egg fried in the mate function.
Use asio async io.create tasks for all three then awaits all three. Okay, I think I don't even need the instructions. Actually, I do need the instructions because I already forgot the co-ine functions that I need. Okay, let me start off by importing a sync.io And then we're going to create an async function or a C routine function called boil water.
There we go. That is going to go ahead and wait. So I'm going to go with wait async io sleep for 4 seconds. Water takes 4 seconds to boil. Guys, in what world does that actually happen? I wish it really did happen here. It' be so much easier to make spaghettis. I'm going to go with something like print water boiled.
There we go. And then we're going to go with something like create an async function called chop vegetables that waits 2 seconds then prints vegetable chart.
Okay, let's go with any sync function called shop vegetables that awaits for uh let's say that sleeps for 2 seconds and then it's going to go ahead and print vegetables chopped.
Okay, perfect. And then I'm going to go ahead and create a third function. Okay, I guess we have three core routine functions. This is going to be called fry_x.
Guys, eventually in the future when like everything is going to be automated, is this how um is this how we're going to go ahead and say the AIS to start cooking for us? It's like call the boil water function, call the chop vegetable function, call actually coine function, and then call the async corine function.
I mean the fried eggs is corine function. which is going to wait for three seconds. There we go. And then the AIS are basically just going to be cooking for us. Okay, let's go with something like eggs fried. But if I'm not wrong, it's F R I E. Yeah, if I'm not wrong, I don't think that um that would be that easy cuz to actually lift those heavy things unless you don't really have a really good equipment. You can't really lift the um should I say heavy weights. I mean there are like grains and everything that can look heavy weights but they are pretty big and heavy as well. I gota fact check that stuff to be honest. That doesn't seem that hard to do. That's it. I'm going to go ahead and define a main function. Wait for this. Add an extra task where you need to guess the order of the prints before you run the code.
It will help you understand what actually happens.
Actually, I might try that for like the next question or like I'm pretty sure by the end of the 30 questions here, that is the task that's going to actually be there because I said to get the tasks uh tasks progressively more complicating.
And that said, I'm going to go ahead and create my task one, which is going to be equal to my async io dot create task.
And hold up guys, I think there's like some background noises. And what is wrong with my webcam? Hold up.
already. Mic testing. Mic testing. Hi guys. There was some background noises.
That's Let's see. So, I create a task and then it requires a C routine function which just calls something like boil water. There we go. And then we're going to go ahead and create our task two that is going to be equal to essential dot chop vegetables um shop oh wait my bad dot create task which is going to be requiring chop vegetables this routine function. Lastly, my task three is going to be equal to let's go with essentio.create task that requires a parameter of let's say fried eggs. Okay, there we go. And then we're going to go ahead and await task one. And then I'm going to go ahead and await task two. And lastly, let's go ahead and await task three.
Okay. And then lastly, I'm going to go with something like essentio dot um run. I want to go ahead and run my main function. XL SR alt n. Let's see. In total, it should be taking 4 seconds.
Vegetables chopped. Eggs fried. Water boiled. Perfect.
Okay, I guess let's go with control arr.
Copy that. I'm going to go ahead and grab plot up here again. And then let's paste it. Okay. And then I'm going to go ahead and say something like done.
Okay, then let's go ahead and send it.
Speaking of which, uh I'm going to go there.
There we go. Okay, that should help.
Okay, that's what I'm talking about. You all you ever need is a single line blah blah blah.
Question two, create task with return values. Quick new concept. 30 seconds.
Read it. Task can return values after you await a task. Task can return val.
Let me decrease my DPI. There we go. Oh, that's too slow now. You should make it a habit to do. Actually, I might call it try that. So, task and return values.
After you await a task, you can grab it result like this. Async define number return 42 task equals to async io.create task task number and then result equals to awaits task print result that is going to be 42.
If dunder name equals to oh hold on guys I actually used to do that a lot. If dunder name equals to equals to dungeon main. There we go. Yeah, guys, this was like a necessity for me to work on um in my programming course. I don't know why did I stop doing it. I'm going to go ahead and return main.
There we go. Okay, make this a habit that does make sense. I'm probably going to start adding this from my I mean um from the next upcoming questions here that said requirements create an async function called wait did I read everything so you can return values after you await a task you can grab its result like this async define get number aren't they manually returning something though I last watched you when you started C++ keep up the grind yo that actually sounds really Cool. I think that was like a long time ago. That said, uh let's see. So task equals to asentio.create task which is going to be get number.
Okay. So we actually get our number that is 42 result equals to await task print result. Oh, I see. Okay. Now create an async function called fetch temperature which requires a parameter of a city that waits 2 seconds then returns city 72 creates a async function called fetch humidity which requires city as a parameter then waits 3 seconds and returns 60% humidity. In the main function, creates both tasks for Austin awaits both prints results.
Okay. Expected output Austin has 72 degrees Fahrenheit. I think that's that's pretty bad temperature. Austin is 60° humidity. I see. Int result equals to await captures the return value.
Create both tasks before awaiting either one. Okay, I'm going to get the instructions in the other window so I can use it. Bro, is it sunlight or tube light coming from the window? It is actually sunlight. Okay, I thought that like I have my OBS on here where I do see if my window or if my webcam gets over the should I say radioactive because the sunlight sometimes just lashes on my face. That said, I try to decrease my game then. Speaking of which, let's go ahead and import something. I'm going to go ahead and get my instructions up here.
Okay. And since I'm going to work with async io, I'm going to go with async io.
There we go. And then let's go ahead and create an async function called fetch temperature.
Okay, that requires a parameter of city.
Okay. And then I want to wait for two whole seconds before I say anything. Uh so I'm going to await my async io dot sleep. I'm going to sleep for two seconds and then we're going to go ahead and return returns the cities's temp temperature.
Here's the thing. Why would I return returns?
Why would Okay, it works like this, but why would I ever want to return something like this? Like, let's go with city. Why not I just use a print statement? We're going to go with city has. I mean, if that if the instructions ask for it. So, I'll do that.
How do you add the degree sign? Uh, what buttons do we click to get the degree sign? I know it was something like 09 or something. 0176.
There we go. Let's go with 0176.
Hold on a minute.
Uh, did I just get Okay, wait. Hold up.
Hold up.
What uh goes with 0176 to get the degree sign? How did I forget this? Alt plus 0176.
So, let's go with something like alt 72 alt 0176.
What the hell? What did I open, guys?
I didn't I just add that stuff. Alt01.
I literally just clicked it. Hold on, guys. Let me go back to my centio. All right, we need to we need to duck here.
Alt 0176.
It doesn't work. How do you add the degree sign? Copy paste from claw the degree sign. I mean, I could do that, but I wanted to know how do you do it.
So, Windows press alt0176 on the num key. How do you All right, guys. I guess I guess I'll copy it from slot. It's all right. It's all right. I mean, it worked before. Why does it not work now? There we go. This is actually an easier way. I could just go online and check it out. That said, once we're done with this, we're going to create another async function. Let's go with async define called fetch humidity.
fetch_h u m i d i t y that requires city as a parameter.
Okay. And it waits for 3 seconds.
Therefore, I'm going to go with await async io.
It's going to wait for 3 seconds before returning me my city. I'm going to go with fring. Let's go with something like city has uh 60% humidity.
There we go. And then we're going to go ahead and create our main function. Now I'm going to create a main corine function that is going to go ahead and let's say create tasks for both functions. My task one is going to be for my fetch actually asiocreate task. Okay. The first task is going to be for me to fetch my temperature.
Okay. And then my second task, let's go with task two is going to be my essential do.create tasks method. I want to fetch my humidity after I'm done fetching or whichever depending on which um which is done first. So first I'm first my fetch temperature is going to be done and then my fetch humidity is going to be done. Then I'm going to go with something like await task one and then I'm going to go with something like await task two.
Now here's a thing. It returns that value. I didn't print it. So, should I print my task one and then print my task two?
Should I do it something like this?
There we go. Okay. So, should I do something like this? And then I could go with something like run. I want to go ahead and run my main function. Let's hit Ctrl Sl.
I run into an error. All right. Before before you guys say anything, I added my awaits.
Okay. And then I added my essentio.create essential test one test two. Okay. Let's remove that.
Maybe because I returned it and I didn't print it. You know what would have actually worked? If instead of returning, I printed this stuff with an F string.
Now I'm going to do the same exact thing here. And I'm going to go ahead and paste it here.
And this is what would really work.
Hold on. Oh my gosh. It's missing one position argument. I don't read my editors. That's where I mess up. What the hell? Let's go with something like, I don't know, Austin. And then I'm going to go with something like uh Austin.
Control S. Ctrl Alt N. Whoops. Ctrl Alt N. There we go. Is it going to return? I highly doubt. Yeah, I knew it won't return squad because in order for it to actually return, I need to print my task one.
And then I need to go ahead and print my task two because let's be honest, without printing, it's not going to return squad.
It's going to say it's the memory address. Wait, wait, wait, wait, wait, wait, wait. Can I go with Assentio?
Um, essentio.run.
But I don't want to run it. I don't want to run it. It's It doesn't print anything because I'm returning.
Rather than return, I need to have a print statement. That's literally the only logical thing. And firstly, my mouse's sensitivity and speed is off the roofs right now.
This is what's actually going to work.
Okay. And then let's see. Austin's is temperature. Austin's is humidity.
Lastly, let's go with if dunger name equals to equals to dunger main.
If that is the case, I want to go ahead and display my main function.
And then we're going to go ahead and grab clot back up here and say um when I returned rather than printing on my go routine functions um it did not print anything.
Obviously, it did not print anything, but I changed it to print now. Okay, here's the thing. And why would I want to print squatch?
Let's see. I know it's wrong here because I was expected to print something.
Hey, I see what you did there. Issue Austin a Okay, it's a typo. Get with the typos. Issue two. Bottom of your code.
Main is in a sync.
You already have a centio main above it.
This line calls the main without a centio. It does nothing but create a coine object. So does your name mean return here? I did that. Print here awaits result equals to Whoa, whoa, whoa.
Result equals to awaits task one.
Results equals to awaits task one. Okay, let's go with result equals to await task one. And what about task two? What about task two? Result one equals to that.
Result two equals to that. And then we're going to go ahead and print our uh result one. And we're going to go ahead and print our result two. There we go.
Now, apparently this is supposed to do the trick. So, I'm going to remove those. And then I'm going to remove that. And then I'm going to remove that.
Let's hit let's get my essential. This is main function right here.
Slone add a none. What the hell? You know what? Let's get that here as well. I just want to see what happens.
none and a none.
Okay, so I get two nuns. Let's hit control arr. Copy that. Let me just go ahead and grab that up here real quick.
Let's paste it and say I get two nuns in um as my output.
And then let's send it real quick. There we go. Okay, so I get two nuns. And hold on, guys. What is wrong with my webcam?
I'm so dependent on the freaking sunlight that my webcam is either too bright or either too not bright. There we go. I should have said, "Damn, that was a record word."
That said, uh, return both.
Hold up. Um, so close. I can see what happened. And of course, my webcam is right here. Speaking of which, let me just grab my bag back there. That was giving me OCD, a tiny bit of bag keeping off. You know what? I think that's so stupid of me. I can just leave my umbrell my configurations out here.
Okay. And then let's hit apply. And then I'm going to hit cancel. I'm just going to keep my configurerations up here and always change it.
That's it. So we go with see you're building the string but not returning it.
How stupid. Oh okay I am stupid. I was like how stupid does clock think I really am? Never mind.
Umio control guys. This is now this is basically silly mistakes at this point. Okay they both execute at the same time. They both execute at the exact same time. The second, let's see the second issue real quick.
The second issue is okay. I did it and it works. But should I or but am I expected to get both print statements at the same time? Question mark. because I get both at the same time. And also, why did we use return and not just rent?
Because that is just so much more convenient and easier. That said, let's send it because uh when we return, we got to go ahead and set that equal to a value and then go ahead and display that value.
Unless we're not really working with a output in our terminal. Okay, great questions. Why do both appear at the same time? Yes, that's completely expected and actually means your code is working perfectly. Both tasks are running simultaneously in the background. Fetch temperature takes two seconds. Fetch humidity takes 3 seconds.
But here's the thing. You're awaiting task one first. Results task one waits until task two. Okay? waits until two seconds. Result two already done by then. By the time task one finishes at task two, task two has been running the whole time too. It only needs one more second. So both results are almost together. Both print fires. The fact that's async working correctly by return instead of print. This is so important.
Listen carefully. Print is a dead end.
The data goes to the screen and disappears. No one else can use it.
Return gives the data back to the whoever called it so you can actually do things. Hi bro, you're hiding a cash.
Appreciate you joining the stream. Oh, there we go. Okay. Result equals to await task one. If result equals to equals to Austin blah blah blah we set our result to a list sent to database.
Oh I see guys I can't really read Hindi. Can you guys um translate that in English?
Okay rooter remember function returns data main or main or the top level princess. Got it?
Now paste your final working code. Okay.
And guys, with this we're going to officially move on to the next uh question.
Let's say done exclamation. Now let's send it. Okay, let's see. Yo, hello.
All right, guys. I guess let's wait for CL to blink. And I do try to use as less tokens as I can with that as well. There we go, guys. I actually like keeping my configurations on. And am I not in the center of my window?
Can I ask you something? Sure. What's up? That's sad. Is it just me or did that just did cloud just absolutely ignore me? Perfect code. Clean, correct, return values captured. Printed from main exactly how it should be done.
Okay.
Question 13. Chaining tasks. finally we're working with chaining. I did work a little bit with chaining when I was um let's say having my programming for two 50day series and I did work with chaining in my C++ I think with my SDL.
Yeah, I'm pretty sure with SDL that was kind of fun. I forgot the concept. So, it's going to be a nice little review.
Write an async program where the result of one task gets passed into the next task. requirements. Create an async function get user ID that requires a parameter of username. Waits one second then returns ID.
What up guys?
Is my lips chapped? Okay. And then gets ID. And guys, this is so much convenient. I can just go ahead and decrease my configuration and increase it. Okay. So returns our user id create an async function get user data that waits two seconds and returns this as a beginner want to learn python so where I study myself what's the progress to learn if you have any playlist please suggest actually I did watch a couple of YouTubers actually at the start of my Python for 100 series like for the first 20 days I did watch a YouTuber but I thought that it didn't help me as much.
For me personally, what really helped me was doing a lot of practice questions and following a road map. If you do want access to the road map, make sure to join my discord server and either go to the programming or let's say the coding helps to chat or python helps us chat and mention my name there. I have two different road maps. One road map is for beginner Python. The other road map is advanced Python which I am currently working on which is basically uh for AI engineering. But if you do want to get started with Python, I have the perfect road map for you. Actually, that was the one that I did use for my Python 400 series as well.
That said, uh, and if you do want access to my Discord server, you could get access to it through the link in the description, through the bio, or by typing exclamation discord on chat all lower case. Matter of fact, let me type it.
There we go. that's going to go ahead and let's say pop a link up.
Okay, I'll get it in both chats. Okay, just give it a quick little minute.
Speaking of which, create an async function that is going to be called get user data that waits two seconds, returns data for user. Then finally we create a main C routine function that creates a task for get user id which is going to be requiring a parameter Austin awaited pass the result into a new task for get user data await that print the final result expected output data for ID underscore austin hence you need the result of task one before you can create task two that means Create and wait.
Create and await task one first, then create task two. This is intentionally sequential. That's the point. I see.
Okay. I'm going to go ahead and let's say grab my Claus's other window on my other screen just so I can read the questions.
Refresh that.
Perfect.
There. Okay. Now, let's go with control A and delete this. Since I'm going to be working with async io, I'm going to go ahead and import async io. And then we're going to create an async function.
Whoops.
I'm going to go ahead and create an async routine function which is going to be called get user ID. That requires a parameter of a username. And then I'm going to go ahead and let's say wait for one second. So, let's go with async io sleep. Let's go with 1 second. And then I go ahead and return something. I'm going to return an string that says something like ID underscore username. Wow.
Okay, this is a whole different convection that I'm actually working with right now. Is going to be 001.
Okay. And then create an asyn is that is my lips literally chopping inside of my mouth? That's it. I'm going to go with async define. Let's go with get user data.
That requires a parameter of user ID that waits for two seconds now. So I'm going to go with something like async io. 2 seconds. And then we're going to go ahead and return an fstring called data for user ID. So this is going to be data for user ID.
Okay. And then lastly, we're going to go ahead and create another async function called main, which is going to go ahead and create a task. Okay. So, create a task for get user ID awaited. Pass the result into the new task. Get user ID. Await.
Then print the final task. Is AI going to take over the world? Actually, AI will definitely not take over the entire world and of course, not even over programmers in general. But here's the thing about AI. If the people are actually slacking and not willing at the peak of what they do, AI can go ahead and automate the stuff that regular let's say junior level or intermediate level programmers actually work with but it lacks the skill of innovation. So even though it can go ahead and do stuff that it's told to do, it cannot really invent new things if that makes any sense. So that's where critical thinking comes in use guys. Okay. And for critical thinking, we do still got to know the basics. But no, AI will not take over the world guys. It will automate half the things which is going to make stuff much more convenient for us. And um one more important thing that I actually think of is that we shouldn't think of AI as something bad rather we should think of AI something that we can use it. Like if we learn to augment ourself with AIS, I believe that we can actually uh let's say be even more effective at these stuffs that we do because let's be honest, back in the days to like search something to Google it all and then read articles. These days, we just ask AI and they do the hard stuff for us. That gives us more time to work on something new. That said, I'm going to go ahead and create task one. You guys could say that I'm biased here, but actually even if I'm not being biased, I feel like jobs related to AIS are going to be peing in the future because um AI is a relatively new field right now. So, of course, there's going to be a lot of demand for it in the next five years. So, you guys got like five years to grind right now.
That said, I'm going to go ahead and create a task which is going to go ahead and require a parameter of let's say speaking of task, hold on, guys. I'm going to increase my gain a little.
Got to have my OBS on at all times to check if my gain is nice. There we go. I wish I had auto configurations.
Okay, so we go ahead and create a task here which is going to go ahead and call my first task which is get user ID.
Okay, that requires a username. I might go with something like V universe.
Okay, so that is the user ID. And then next up await it. So we're going to go ahead and await our task. Let's go with result one equals to await task one.
Yeah. And since I'm returning a value before awaiting it, I do need to store whatever uh return value I get. Await it. Pass it to the new task.
Okay. So, awaited. Oh, wait. Never mind. I can't go with Okay, it's fine. It's fine.
Awaited. Pass the result into new task.
Forget user data. Await that print the final result.
Okay, so we're going to go with something like result two equals to await task two. And yeah, I did not really create task two yet. Task two equals async iocreate task.
Okay. Uh, let me decrease my gain a little. What is async IO? Hold on, guys.
I'll explain that in a bit. Uh, well, if it's testing at micro level, it's going to create something completely new because we can't test so quick. That does make sense. But here's one more thing. It can only work with the data that it's got. Unless it has like way too much data that it can start making new things. That's a whole different field, guys, in like the what's called the agentic AIS section. But that is definitely possible. It's going to be kind of cool eventually. It'd be so cool if I could actually make a literal AI that could like stay with us as our personal assistance and like also do these stuff that we tell it to do, of course, as a partner. That's sad. Okay.
Now, basically what Asyncio actually does is that it makes stuff more convenient for us to work with. For example, let me uh the example that I just gave another guy who asked me was that imagine I'm a waiter and there's a customer. I go and I ask the customer for its order. So I requested something.
As soon as I get its order, I move on back to the kitchen and I I give the chefs the order that the customer gave me and then I stand there and I wait for the chef to prepare the dish. Once the dish has been prepared, I grab that dish and give it to the customer and then I move on to the next customer and repeat the process. That is really ineffective if you're if you're like working with a lot of databases or like a lot of customers. So what asyncio actually does is that it gets the order from a customer, gives it to to the chef. While the chef is preparing the dish, it goes to the other customer, gets the order, gives the second order to the chef, goes to the third, and once my order number one is done, I'm going to fetch my dish and give it to my customer. If that makes any sense. So, nothing is pausing.
What what's done first is uh whatchamacallit is uh given to the customers first. Oh god, it's like execute a few instructions simultaneously.
Okay, that's that was an easier way to put it. What are you making? I'm not making anything right now. I'm working with the basics of AI engineering. Then later on at like days 300 or like three Yeah, I think like 300 or like 310, I'm going to start working on my main project or my main goal which was to create an agentic AI like how a GPU operates. Guys, I'm going to get a GPU soon. That's let me read the instructions.
Okay. So, we go with something like create task. Of course, I had a typo.
And I'm going to decrease my gain a little as well there. Okay. Now, for my create task, I'm going to go ahead and grab my get user data here. It requires a user ID as a parameter. Oh, wow.
My user ID is going to be my test one.
Or well, my result one, I mean.
I'm going to copy that and then I'm going to paste it here. And then we await this.
Okay. And then we print the final result.
Print result two. I wanted to print result one for the fun of it, but it's fine. Then I'm going to go with if dunger name equals to equals to dunder main. I want to go ahead and go with async io dot run my main function. I spelled them absolutely wrong. A CPU executes instructions in a linear way.
Honestly, do you guys think that it's going to be smart for me to learn about hardwarees as well? Because I did not really work much with hardware like CPU, graphics card and all that. I know how to make it PC using those things but I can't really um tell what they do internally from what I understand. I see. Now if I run the program, we get an async io. Eerror enable trees. Now when you call a function, did I go with a wait? There we go. I make this mistake so much. It doesn't help that I talk more than I actually type here.
There. Now data for Viv universe blah blah blah.
And then let's go ahead and print my result one as well just for the sake of it or the fun of it.
This is going to give me the ID V universe one data for web universe one arr. Now let me go ahead and get a web plot up here. Then we're going to go ahead and paste it and say done exclamation.
Guys I just realized how many questions are 30. There are a lot. Speaking of which, if I were to go ahead and open my road map here, uh what is the next topic that I got to work with and how long is it going to take before I'm really done with it? So, we got Oh, wow. I'm still in the second part, guys. I guess a good analogy would be uh while waiting for a dish to cook, you might clean the dishes. That's actually the perfect way. Okay, that is so much better than the like five minutes worth of instructions that I gave or like the lecture that I gave like get this order, give it to the chef, get another order, blah blah blah. That was that was an easier way. I might actually say that to the people.
Okay, so next up I got to work with type hints and pantic for data validation virtual environments and dependency.
After we're done with that, that's basically all we need for our advanced Python.
What does the await function do?
Basically, what the um await function does is whenever we're trying to get a program that is supposed to be asynchronous, that is supposed to like do tasks while some other tasks are waiting, we need to make sure to add the weight keyword because without it, we're going to run into an error. And I have a better I have like a better explanation in my notes there. await pauses the current C routine and yields the control back to the events loop until the awaited thing is done. Corine functions are basically um any functions that has an async in it. So this is considered a coroutine function and the result of it is always going to be an routine and we got to always await the corines.
Oh god guys, this is this is getting like a tongue twister. Okay.
can only be used inside an async's define py Python async define example. Okay, await async async io. Pause your let the other corines run. Oh, so basically what a quarantine is, I mean basically what the await function does is that while my sleep.1 is still in progress, while my um let's say let's pretend this was 10 seconds. While this function is still waiting, I won't stop here. I'm going to move on to the next corine function. So my longest the program would ever take is the one that takes the longest time to really give a result if that makes any sense. Oh, I noticed you switched away from jet brakes. Why?
Oh, you mean like pygame? I mean PyCharm. I don't really know why because I would actually I would have used PyCharm but I thought that I already had Visual Studio installed and I was like might as well use Visual Studio.
That said, I think that was pretty much it, right?
I'm going to go ahead and grab cloud here. All right, guys. Question 14. We got like 16 more questions to go. What the hell? Task cancellation. Quick new concept. There are a lot of concepts in these 14 functions. Oh, god. You can cancel a running task manually using cancel or the dot cancel method. Task equals to async.io.create create_task some quarine task. cancel cancels it.
When you cancel the task when cancel the task raises async io cancel error inside itself. You can catch it. Try a wait task except async io.ancer.
Print the task was cancelled.
Okay. The code editor. Yeah, I mean PyCharm is actually really really good, but I think that since Visual Studio Code does the same exact thing, I was like, might as well use it. Next up, requirements. Create a sync function called long operation that prints operation started. Waits 10 seconds, prints operation done. In the main function, create the task, wait two seconds, cancel it, then catch the cancel error and print operation cancelled. Operation started, operation cancelled. Hint blah blah blah. Okay.
All right. This shouldn't be that hard to be honest. I'm going to get the instructions in my other window just so I can use it as a reference. While I'm at it, I'm also going to decrease some of my gain because why is it so why is it so bright?
There we go. That's much better. Okay.
Now, I'm going to read the instructions there. Again, since I'm working with async.io, I'm going to go with async.io.
And then I'm going to create an async coin function called log operation.
And also speaking of which I just realized it's been so long since we last ping formidable thunder. Okay. And then let's go with long operation that prints something like operation started dot dot dot and then we're going to wait for two seconds. So I'm going to wait for async ios sleep 10 seconds. Yeah, I meant 10 and I said two. And then I'm going to go ahead and create a main async core routine function.
Okay, that creates the task. So we're going to go with something like async io async io.create task. I want to create a task for my long operation.
Okay, that is not going to require any parameters. Although I'm going to wait for two seconds, then cancel it. We wait for two seconds, and then we cancel it.
Here's the thing, bro. What happened to our game development? That was actually just a series. So, it was called my programming for two 50-day series where my goal by the end of that series was to make a game in general that consisted of AI logic in it. I was done with that.
You guys can get access to my game by typing ex or actually through the link in my bio. I just need to make sure what happens if I type exclamation it. Will this give you my it's link? I'm pretty sure not. I forgot to set it. Hello, bro. I need to ask something. What's up, Burnt? Okay, let's see. Uh, let's go with task one. Yeah, guys, I don't really have my it says link, but well, if you guys do want access to it, you guys can. Let me grab this here.
Okay, you guys can go ahead and move on to my channel here. And under the more y'all can uh find my Where is my it.io? There is no way I didn't send I didn't set it up here.
Maybe in my description. You guys most likely get the gist of it. It's It's seriously not in my bio. What the hell, guys? I'm selling out here. Hold on. Let me add in my buyer right now.
Okay. And then I can go here. When do you start coding? Actually, when did I actually start coding?
Okay. So, basically when I actually did start was in my oldest stream, which was nine months ago. Um, add two more months to this. So, nine actually, let's go to my videos. So, in my videos, there we go. So, I started coding 11 months ago. This was basically the first ever time when I started my Python for 100 series. It's a very bad video cuz my mic wasn't that good and all that stuff.
But yeah, that was basically it. Um, I uploaded I uploaded this video seven days after I was done because I used to give you guys a weekly update as to when I started programming or not. That's going to go ahead and work on the question. And guys, yeah, I did not really have my H.IO's iOS is linked right here, but I can actually upload it on chat just for today and then later I'll add it back.
I might go ahead and click my project, copy that. There we go. Okay, that is the link to the game if you guys actually want to check it out or I have an entire um YouTube video on that as well and also a stream. Speaking of which, I'm going to create a task here.
Okay, wait two seconds. So, I'm going to go with await a sync io sleep. I'm going to go ahead and sleep for two seconds.
And then we're going to go ahead and catch the cancel error. Okay, cancel it after two seconds. So, I'm going to go with task one.
And next up, we're going to go ahead and try something. I'm going to try.
Wait, we're supposed to try our catch, right?
Hold on a minute. Let's go ahead and try this.
Okay, so we're going to try that and I'm going to go ahead and accept my cancel error.
Is this not Is this not like a legitimate error name?
Cancel error is not legitimate. Oh, maybe maybe async IO. There we go. This makes so much more sense. So, it's async IO's cancel error. In this I'm going to go ahead and print operation cancelled cnc l.
There we go. So operation cancelled expected output yada yada. Therefore let's go with something like if dunder name equals to equals to dunder main.
I'm going to go ahead and uh go with my async io run. I want to run my main function.
So operation started. Wow, it just started. So uh what do you do? Are you working professional or a student? If you're a student, which class/ year are you in? Actually, I am like a student.
Uh what should we call it now? I'm a freshman for now. That said, um yeah, and when I say freshman, I basically mean that uh the stuff that I'm learning right now or the stuff that I work on my stream is completely different from what I really work on my college. In my college, I'm an absolute beginner on stream. I have almost a year worth of worth of experience. Next month is officially going to be a year-long anniversary of me programming.
What should I do for it? Maybe nothing actually.
Okay. And then we create our task one.
And then it didn't really uh cancel my test, did it?
Operation started. And you started from scratch just 11 month 11 months ago and now you code everything on your own.
That's incredible consistency. Honestly, that does make that does actually mean the world to appreciate you burn.
Speaking of which, I'm going to go ahead and copy this. I'm not really as familiar with these syntaxes here. Well, um Oh, wait. Wait, wait, wait, wait.
Okay, so I did await that. You know what? My bad. I think I had I should have awaited that.
Yeah, if we don't await stuff, we get all sorts of errors. That's fast.
Okay. And then we await that cancel then await task one inside.
So try await task.
Okay. So wait, we try await task in sync some coine function and then we go with something like cancel. Okay, it's all correct. What? Why do I get this error?
Task one is not defined. Oh, guys, I'm so stupid. What the hell?
Okay, this is this is basically this is just syntaxual error. This is this gets better with more practice with control alt n operation started.
Operation no comp. Okay, the program is going to run for like 10 whole seconds I think.
Wow, the 10 second gives no attribute.
Your Instagram link and bio isn't working actually. Really? You could try exclamation um Instagram s d a g r.
There we go. I think the bio one is outdated. I got to update that.
Okay, this should work actually. Like if you click that.
There we go. Okay, that works. Let's exit it. Okay, now let's see. Uh create the task. Wait two seconds. Cancel it.
And then catch it. So I created a task.
I waited two seconds. Okay, I want to await it here. I did actually await it here, did I? And then accept async.io cancel error operation cancelled.
I did it, but I don't really get a cancel error. Let me grab plot up here real quick. And then I'm going to paste it and say I feel like I messed my syntaxes up.
And then let's send it. Okay, this shouldn't be as hard as it looks like it is. Yes, you did. But you spotted it yourself. Blah blah blah.
Away operation.
This waits for the entire task to fully finish before moving on to the next line. So task one.ancel never gets reached. Task one already run completely. Create task. Task one go with async.io log operation. Await task one. Await task one sets in background. Let's do second cancel. Let's await it here.
Okay. So it's basically task one and then we sweep it. We cancel it and then we try.
Basically where I messed up here was that above the I'm going to add pass as a placeholder for now. Now above my try and accepts we go with async.io dot um did I already forget what the hell?
Okay. So first thing we're going to await our test. I'm going to go with task one equals to async io dot create tasks function. I'm going to go ahead and create a task here which is going to go ahead and be my long underscore operation.
There we go. Now my long operation task once it's created I'm going to go with await async io. sleep. I want to wait for two seconds after my task has uh started.
And then I after the two seconds, I want to cancel my task one.
I spelled it wrong, didn't I?
There we go. I want to cancel my task one. Then I want to try to await my task one because this is where I'm going to go ahead and run into an error. If I ran into an an async io.ancel cancel error.
It says operation cancelled. If I to run the program, op started op canceled.
Okay, it works. But I got help for this question, so I don't really take full credit for it.
Work exclamation. I see how cancel works now.
Okay, let's see the next question. Yo, how you doing, Anime Haven? I appreciate you joining the stream.
That's it. Quick recap what you just learned. Create underscore task. Never await on creation. Await async.io.
Give the task time to run first and then task. Send the cancellation signal.
Await task inside try/accept.
That's where you catch it. Question five. Task cancellation with cleanup.
Requirements. create an async function called download file that prints downloaded file name prints file name download complete and then in the main function start the task wait for 3 seconds why the freak you use claude in light mode because I don't really have my windows key so it can't really be converted to dark mode and I have been doing this for like I think like about half a year now I've been using it night mode so I can actually see this stuff.
Speaking of which, the brightness is by god so low. Can you guys actually see me change my brightness?
Oh, wait. You guys can because of my webcam. Let me hide it.
There we go. If I do that. Oh, you guys cannot see. I think that's the stuff that only the bios can see it. But yeah, my brightness is really low right now.
So, I think that kind of um adds up for that. But I hate I hate light mode as well. That said, um, in the main function, start the task. Wait three seconds, cancel it, catch the cancelled error and print download cancel, cleaning up the file name. Expected output. Downloading report PDF. Download cancel cleaning up the report.pdf.
All right, guys. Let me get the instruction in the other window. Is it just me or is it actually getting really hot? Do you stream every day? Yeah, I do stream every single day. If you guys do want to get updated for whenever I stream or not, I always mention you guys on my Discord server whenever I uh go live. For example, if I were to open my Discord server right here, and you guys could move on to my horizontal stream if you guys want to see my entire video.
That said, um just grab that up. There we go. Okay. In the announcements, make that there. So every single time when I go live uh the number of days is sort of written here and all that stuff and for all my streams I do mention you guys and all that but one really important thing when you guys really join the discord server and don't do is that you guys don't get roles like um you guys will not be able to have access to these most of these channels here if you guys don't have the roles for example in the genre's channel if you guys only have the gaming lovers uh gaming lovers' role. You guys will only have access to my gaming chat. If you guys have only coding lovers as role, you guys are going to have access to all the coding chats, the coding help chat, and the coding voice chats. Universal chat is for general. Oh, where's your discards link? You guys can get access to the discord by typing exclamation discord on chat and uh through the description and the bio. And the exclamation discard is going to be all lowercase. Let me actually type it. There we go.
That said, moving on to the question now.
Let me get the instructions there. There we go. Okay, guys. I'm kind of out of breath. What the hell?
Actually, I'm not really out of breath.
It's just pretty hot out here. Let's Let me go ahead and open this real quick and bring some water.
Speaking of which, if you guys do want to um also get access to my road map that I'm currently using for this series, you guys could either go to the coding helps us chat or Python helps us chat.
My bad guys, you guys could either go to the coding helper chat or the Python chat and mention my name there at Viv Universe and ask me for the road map. I will be personally DMing you guys the road map. That said, let me just accept that. Okay, let's go ahead and work on the um question number 15. Right, halfway there, guys. 15 more questions to go. Since I'm going to be working with async io, I'm going to go ahead and import async.io. And then I'm going to create an async routine function called download file, which is going to be requiring a parameter of a file name. And then I'm going to go ahead and print downloading file name which is going to be like an F string.
There we go. Downloading a curly braces file name that is going to go ahead and wait for 10 whole seconds.
Async ios sleep 10 seconds. And yeah, I know I forgot to wait.
There we go. Okay. And then once we're done with that, it prints file complete.
Aren't you learning Python for webdev?
Actually, I'm learning Python for being an AI engineer. Actually, my current CV that I'm working on right now is AI engineering for 365 days where my goal by the end of this series is to make an agentic AI. And in case you guys aren't like familiar with agentic AI, they're are completely automated AIs that work based on all the data that they have as opposed to following the rules that we tell them to follow.
Are you learning Python or webdev? I'm actually working with Python. I'm learning Python right now. That said, let's go with something like Pinch.
My file name downloaded complete.
Okay, let's go with something like download complete explanation. All right, guys.
It's getting really hot here. Next up, I'm going to go ahead and create a main function. So, as y a main uh corine function that is going to go ahead and start the task. So I'm going to go with task one equals to my async iocreate task which is going to have a core team parameter of my download oh god of my download file that requires a file name which is going to be called something like report. I don't know what is my file name going to be. Can you use numpy?
Actually, I was going to work with numpy back in my Python 400 series, but I started a brand new series. Although hopefully by the I mean hopefully for this series since I am working more with Python, I will be working with NumPy.
I'm 100% sure that I will work with machine learning and all that stuff. But if numpy is in my road map, then I'm going to work with it. If it's not, then I could later on have a minieries because I always wanted to try like numpy, pandas, and turtle. There we go. Numpai, pandas, and turtles. I wanted to try the three of those. That said, why am I talking so fast? Okay, because these days I I did I do like try talking a little bit slower as opposed to my previous streams where I used to like just gamble on. That said, I'm going to create a main function. Start the task. Wait three seconds.
I'm going to wait my async.io for 3 seconds.
Okay. And then we're going to go ahead and cancel it. So I'm going to go with task one dot cancel.
Okay. Now cancelling does give me an async IOS's um cancel letter. So I got to catch that. Can I see our road map? Actually, it's right here. I can show it to you guys on stream as well. But if you guys do want the entire road maps PDF, you guys can either go to my coding helps chat or python chat in my discord server and mention my name there. I will be personally DMing you guys your road map. Yeah, this is a road map that I'm currently working with. It says I'm currently on my async.io.
Next topic is going to be dipens and p by dantic for data verification. Hand gestures are funny actually because I think they're really really funny. This guy is insane guys. Insane. It's kind of crazy. I will be working with pandas. I did not know that. Wow. Okay. So we're going to work with cleaning margin reshaping data and then polers faster faster alternative increasingly standard in production and then we're going to work with databases SQL mastery. Okay, N OSQL basic for [ __ ] databases and then OMS. I haven't actually heard half the stuff here. That said, oh no, we're going to work with linear algebra. Okay, it's not like I hate algebra. I'm just bad at math. I guess it's going to be a fun little time there. And then we're going to start with classical machine learning. Wow.
And then model evaluation.
I've never seen those functions before.
Those functions do you mean like wait let me just go through the entire road map. There's tensors data sets training loops building networks from scratch the transformer architecture and then we have rag. I have heard about rag but I haven't ever tried it. And then hybrid search graph rag rag evaluation multimodeling rag. What the hell is rag?
There are so many rags here. Finally like uh 75% of my way till the end of this road map. We're going to start working with local llms we lm blah blah blah. I'm just going to quickly skip over everything. Python functions LM can trigger memory systems agent safety LM cloud deployment git GitHub all those basic things wow this is a long road map that's it if you guys do want it make sure to go to my discord server the coding hub chat python chat mention my name then I will personally DM it to you guys okay now about the question about the um comment that I've never seen those functions before do you mean these async functions they're called core ordin functions. They're mostly used when it comes to um let's say receiving data without really stopping and waiting for the data. For example, I'm going to give you the same example that I give everyone. Imagine that I'm um a bartender and I'm going to a table and asking you what order do you want to give me? When you give me an order, I go to the head chef and give the order to the head chef. While the head chef cooks, I wait there. Once the uh let's say head chef is done cooking, I'm going to grab the meal and come up and give it to you. Why would bartender grab a meal? Let's say grab the alcohol and then give it to you or you guys get the gist of it. But that's a really bad way to work with this stuff. But then when we work with async define a co- routine function, async define basically creates a coine function. It's called an asynchronous way. So when we use these kind of functions, I go ahead and ask a order, give it to the head chef. While the head chef is actually preparing the dish, I go to the next customer, get the order for the next customer again, go back to the head chef, so on so forth.
Which work is done first? I give that customer their order first. if that made any sense. Because when working with like LLM models and all that stuff, you want to go ahead and grab the data that you receive first and not wait on the data that comes before it.
Guys, I make that sound so complicated.
That said, let's work on this function now.
So, we go ahead and cancel it and then let's catch an error. So, I'm going to try now. Let's go with try. Let's try my task one because when we cancel um a coine function, we get an async io.canc error. So I want to catch that.
Therefore, I'm going to go ahead and accept async io dot cancelled error. There we go. It's not cancelled, it's canceled. So basically, you've been learning Python for over a month. Actually, just a Here's the thing. I have already worked with Python for my Python for like a 100 series where my goal was to make a game. I did make a game using Py games back then but that was mostly software development and actually game development in if I were to be more more specific but the game development is completely different from what I'm working on right now. So you could say that I've been working with Python for like eight days for the time being. Although the syntaxes are similar, just the context functions and the way I program is different. If that makes any if that makes any sense. Guys, I think I should work on my phrasing. Speaking of which, and print a download cancel.
There we go. Cleaning up.
Okay. And then I'm going to go with something like my file name.
Okay. This is supposed to be an F string in that case because I do require file name as a parameter.
Task one. Can I use this as a function?
Download cancelled.
Cleaning up file name. How the This is not an object. I can't really go with my file name unless it's not passed in as a parameter.
cleaning up my task one which is going to return my file name. So yeah, I'll say soft. So here I'll say software engineer as well. Actually I do have like a lot of software engineering um should I say experience but then for the time being let me just go with something like report.
Yeah, but then I'm not going to be having that much knowledge about it in the future because right now I did work with SDL3, Unreal Engine and regular C++ as well. But then for my AI stuff and all that like for the AI engineering, I think that I will rarely be working with uh game engines or like graphics libraries and all that stuff. Hopefully I get to work with Unreal Engine again because I sort of liked how that worked and I spent a lot of days working with Unreal Engine. Have you not been working on C++? I did actually because back in the days I thought that um game AI and generated AI were the same exact thing.
But then 150 days in my programming for 250day series, one of you guys did point out and tell me that generated AI is different from game AI. That's when I was like, oh shoot, I wanted to go with generated AI because initially my goal was to make an AI who I could actually talk with inside my game. It's like a brand new player. And that was way too ambitious at the time, but I thought it was possible. Like, have you guys ever heard of the Arcaninator where you give it a word and it tries to guess it?
Something like that. But then that was too complex. Later, I realized that I didn't really like game development. I just like the AI part of game development. So, I thought to work with AI engineering and give it a try.
Speaking of which, cleaning up.
Okay, we have PDF prints downloading file name.
Okay, we have downloading file name then main.
It catches the error and print download cancel. Wow, amazing stuff. That actually sounds kind of cool, guys. That said, guys, um game development is one of the most tedious stuffs. It doesn't look that hard, but it's actually really hard. When I first worked with it, I realized that let's go PDF. Okay, I thought that it's not going to be that hard because it's basically just adding game and some code, but no, you need to add the actual sound effects, the V effects, the walk steps, and like every micro detailing that happens in the program. That was really hard. And since I was like a solo developer that I had to make all those sound effects myself, I'm gonna upload a video on like my one stream where I did actually voice act for all my um actors in the game or for all my sound effects in the game. And that was absolutely hilarious. I became a whole video guy back then. Better than analyzing stresses on bridge than drawing sheer stress and bending moment.
Okay, you know what? I may be thinking the same thing right now cuz I still am a beginner when it comes to AI engineering. For all I know, it could be equally as hard or potentially even worse than game development. Okay, file name needs to be accessible inside your file name needs to be accessible.
Everything else you already know. So file name is supposed to be accessible, right? How about this? How about I return?
I can't really return, right?
File name. File name. I want it to be accessible.
Diagrams.
Oh, that does make sense. That said, you know what? I won't make it accessible for now. I'm just going to check it up.
Okay, I think that's pretty much it. I'm going to go with something like if dunder name equals to equals to dunder main. I want to go ahead and let's say call my main function. Nope. I want to go with async async io. I want to run my main function through my async io.
Downloading report download cancel cleaning up report.pdf.
But I sort of did hardcode my report because I don't really know how to give it access. So I may actually move up move one up here. Then let's paste it and see something like um something say I mean it did work but I hardcoded my file name.
There we go. But I hardcoded my file name. I did not know how to pass it. And then let's send it. And guys I think 15 questions is like my limit for this stream here. That said, good that you caught it. And also because I am going to be recording my programming for two 50-day series, part seven, which covers from days 151.
Really depends. I usually go in like increments of 25 days, but then I'm almost out of my summer break and I need to start my college soon as well. So, I got a pre-study. So, I might go with days 150 time lapse all the way till day 200 or something like that. Well, it depends. I want to be done with my montage review ASAP.
That said, file name equals to report PDF task one file name. Oh, we don't hardcode it.
report PDF.
Okay. And then this is going to be my file name. Guys, that was so stupid of me. I do know how to do this. This proves that I'm exhausted out here. Then this is going to be my file name.
there. Control S control alt 10 downloading report PDF download cancel cleaning up report.pdf PDF where there wasn't any cleaning up to be done here, but you know, it's all right. Let's paste it and say something like done exclamation.
I get the gist of it, guys.
Logic is perfect. You nailed the file name variables.
Okay, both places where it appears. Go.
But download file is still in there. The same typo from last stream. Oh god, >> of course that's my typos.
Download file.
I'm going to copy that. I'm going to paste it here.
And then we have a download. Download.
Download. Download.
Okay. Downloading report.pdf.
There. Guys, this is one thing that I sort of love about Claude is that it's so picky when it comes to seeing my code and all that stuff. Let me say done. It wants me to have no typos and it needs to be exactly as the instructions asked it to be. You've completed questions 9 through 15. Look at what you did today.
Um, now, how did it know that I was going to end? Guys, I does plot can does plot have access to my microphone or something? How did it know that I was I was actually exhausted?
Seven questions in one screen. You showed up. You grinded. Blah blah blah.
Now before you go, do you want to keep going with question 16? Call it here.
Get your transfer prompt plus section notes.
I think option B because I am sort of tired and that I need to record another video.
Okay. And then let's send it. And yeah, I'm going to get a transfer prompt and all that so I can give it to the other chat. Speaking of which, why did I open my Dainci? God, what is wrong with my Unreal Engine configurations?
Hold on a damn minute, guys. There we go. Much better. And then I'm going to go to my main camera. Let's hit apply first. And then let's exit that. Then I'm going to hit okay. Perfect. Let's go to my main camera. All righty, guys.
What is wrong with my webcam again? Oh my gosh, guys. Every time I got to go to configure video and like decrease it. I wish I had like auto configure or something.
That said, uh that was basically it for the stream. If you guys didn't enjoy the stream, don't forget to smash that like button, subscribe with the notifications bell turned on, and also share this uh stream or my channel in general because liking my algorithm. Sharing makes my subscribe.
The sun is ruining my also perfect intro outs here. By the way, I am trying a new intro by saying that smash that like button. Back in the days, I used to be like, make sure to like, share, subscribe.
Of course, guess we got to decrease our exposure to the negatives. Now, before the sun goes off and also I will start mashing on Twitch and TD followers a requirement.
Now, I will start streaming on Twitch and Tik Tok once I get a better graphics card, which I will be getting relatively sooner. If you guys do want to know the current specs that I'm using for my PC, make sure to type exclamation specs on chat all lower case. It's going to show you all my specs. That said, I will start streaming on Instagram and Tik Tok as well. If I did meet the followers requirements, if you guys enjoy my content and haven't followed me there, make sure to follow me there. The link is going to be in the description. The link is going to be in the bio. And you guys can get access to my um Instagram or socials in general by typing exclamation alongside the socials's name. If my social does exist, it's going to go ahead and give you guys a link. If it does not exist, it's just going to not give you guys anything.
And the link I mean the socials name is supposed to be all in lowerase. And also join my discord server. That's where I usually talk to you guys, chat with you guys, have general conversation with you guys. The link is going to be in the description. The link is going to be in the bio. You guys can get access to my discord server. We're typing exclamation discord on chat all lower case as usual.
And if you guys do want to whatchamacallit join me in my AI engineering for 365b series and you guys want the road map that I'm actually using for it, you guys can go to either my coding helps chat or pythons chat and mention my name there at web universe and ask me for the road map. I will be personally DMing you guys my road map.
That said, I'll catch you guys next live stream or video. Peace. Okay. Wow, the sunlight had to go now. Okay, I guess let's end the stream.
Related Videos
Agentforce NOW AMA: Build with React and Salesforce Multi-Framework
SalesforceDevs
490 views•2026-05-28
How agent o11y differs from traditional o11y — Phil Hetzel, Braintrust
aiDotEngineer
450 views•2026-05-28
WEB TECHNOLOGIES UNIT-2 | Degree 4th sem BCOM Computers web technologies unit-2 full explanation💯✅
LearnwithSahera
1K views•2026-05-29
More tests are always better? How to use AI to identify tests that bring little value
Alliance4Qualification
335 views•2026-05-29
Search Algorithms Explained in 60 Seconds! 🤖💨
samarthtuliofficial
218 views•2026-06-01
People of Game of Thrones using JavaScript DOM
AltCampus
296 views•2026-05-30
Introduction to Problem Solving Part - 1 | Lecture 1 | Intermediate DSA
ascensionix
107 views•2026-05-29
🚀 BCS613C Compiler Design | Module 1 to 5 Schema Evaluation 🔥 | VTU 6th Sem 💯 #VTU #bcs613c #exam
Pranavaa-y4y
104 views•2026-06-02











