In Python's asyncio library, a Queue (q) enables efficient task distribution between producers and consumers using put() and get() methods, where await is required for blocking operations like put() and get(), while task_done() signals completion; sentinel values (None) provide a cleaner shutdown mechanism than manual cancellation, allowing workers to gracefully exit when they encounter the sentinel value, and asyncio.PriorityQueue enables prioritized task processing where lower priority numbers are processed first.
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 10/365)Added:
Oh my god.
Heat. Heat.
Already my dusty mic. Okay, perfect. Going to go to a main camera. All right, we're live.
We're live. And as you guys can tell by the thumbnail, today is day 10 of my AI engineering for 365 days series where last game I didn't work with async io away slash um I think. Oh, async io async/way. There we go guys. The name is way too confusing. Speaking of which, I did stop at question number 15 and today I was about to work with question 16 all the way to questions 30. So hopefully I can complete all those 15 questions because by God this topic is so easy but really tedious as well because the smallest mistake actually gives us an error and there are pretty much new things that I am learning as well. Speaking of which, let me go on to my game play screen.
There we go. Okay. And guys, I did create this brand new chat yesterday. So I did not have to do the struggle of creating it today. Let's let's say something like since I'm live exclamation.
Okay. And guys, since I am working a little on playing Valet as well for like the upcoming series, my monitor is kept so close to my face, so there's not much space for my keyboard. So, I'm just going to leave it here. What's your goal? What role do you want to land a job in? Definitely AI engineering.
Speaking of which, let's get it. No warm up. Straight to work. Wow. No warm up.
New concept. Async.io.q.
Guys, how many methods does this asyncio actually have? Because question 16, before question 16, you need this weapon in your arsenal. Basically teaching me the prerequisite before I really work on a certain topic. That said, a guys, I'm going to go ahead and move on here. Let's go to English to Japanese. I don't know why I always pick Japanese here, but let's go ahead and paste the word. Let's see the pronunciation.
>> Q.
>> Q. Okay. So, a hue is a line. A hu is a line. Tasks go in one end get processed out of the other end. It's basically like a tunnel. In that case, this is how real AI pipelines pipelines work. A job pile up, worker chew through them. I see. Are you in college or high school?
Actually, I am a freshman in college.
That's it. So firstly, we import async io as usual. And then we go with hue equals to async io. Hugh method await hue.put item.
Wow, our hue has methods in it as well.
Okay, add something uh to the line. So I want to add item to my users line and then item equals to await q.get pull the next item out. Q.task done signal that item is finished. Await u dot join block until all item are task done. Block until all items are task done. Ah I see okay okay. The pattern producer/consumer async defined. So we create a C routine function called producer that requires Q as a parameter and then we await our Hue.put job one. Producer loads the Hue and then await Q.put job two. I'm assuming producer loads the Q again. And then we create another corine function that requires u as a parameter.
We set item equals to or we create a variable item and set that equals to q.get consumer pulls the heel print processing item. Q dot task must call this or join waits forever.
Producer puts work in consumer pulls work out. I see. Hu. Join waits until every item has been task done. Okay. This is the backboard of agent task routine. Learn it called. Question six. A job Q with producer and two workers. Task. Build an async job Q system where one producer loads jobs and two workers process them simultaneously. Requirements. create an async io. Hue producer put six jobs in the hue. job one through job six prints q job_x which is basically going to be the job number I'm assuming for each worker name and a hue loops pulls in case we're going to be using loops pulls a job prints worker a processing job_x we wait for 1 second print workers done blah blah blah and call the task underscore done workers stop looping when The hue is empty and all items are done.
Okay. So, wow. Oh, wow.
Okay. Workers need while true loops uh they keep pulling until cancelled. After hud.join resolves cancels both worker tasks manually. Worker task.
Same pattern. You use question 14 and question 15. Okay. get those. Where were you actually used the cancel? Okay.
Producer is just a regular await, not a task. Run it before launching. Okay. It does say don't overthink it. I was about to overthink it, but I guess I guess we're not going to. And yeah, this is the um notes from my last streams video.
So, if you guys do want to check it, let me know on my Discord server. I can actually give you access to these notes.
That said, I'm going to go ahead and let's say move on to my async io. Let me exit that. Where is my async io? Hello. There we go. I'm going to go to my async ios's um py file. Then let's exit this. Now I'm going to actually open my not in the order window so I can use it as a reference because I want to read the question as I answer them. Let's uh let's go rub that there.
And also one small small little thing here. I'm going to go to properties, configure video. Wow, my gain is max.
I'm going to go ahead and just leave this out here and then hit something like okay. Now, if I change this, my webcam's gain increases and decreases.
Maybe I want it to be a bit more brighter. I might increase the exposure.
Doesn't make it laggy, does it? Okay.
Okay. And then I'm going to decrease by the gain. And in case you guys want to start streaming, this is what you guys should um sort of learn.
Okay. I'm going to leave this in the other window. Then we're going to grab that. Get that there.
All right. Perfect. Let's move on to question six.
I'm going to close that. There we go.
Okay. So firstly, build an async job system. Okay. So I got to create an async iosis Q. So firstly since I am working with async io I'm going to go ahead and include async io and then excuse me guys I'm going to look at the reference as well we're going to have to create a hue. I still don't get what hu means but okay q ue e u e. So q u e u e q is going to be equal to my async io dot there we go dot q oh oh so it's going to be uppercase with a proof of parenthesis because this is a hue method and then producer put six jobs in the queue. So for my producer I'm going to go ahead and create a corine function. So async define producer.
Okay, my producer is going to be requiring a parameter of my U.
And then inside a producer, let's see.
They put jobs. Here's the thing. I forgot how to put jobs. Hold up. I might look at the reference real quick. Okay, so Hue.put. So we use a put function here for our um jobs. Okay. So, we're going to go with something like my Q parameter.put.
I want to go ahead and let's say put something like job_1.
There we go. Okay. And then I'm going to await this as well. Let's await.
Now, here's the thing. Is my await valid here? Okay. Well, it is valid. And then we got to go through job six.
So put six job into the hue job one through job six prints. Hu job for each.
How will it print that? But okay, I guess let's let's just go ahead and um add a bunch of jobs here real quick.
There we go. Let's paste it there.
There. Whoops. That's one, two, three, four, five. And this is supposed to be six. Now we basically just change the number here. That's two. That's three.
That's four.
That's five. That's six.
Okay. So we put six jobs in the hue and then it prints H job. Okay. How do you how do you do that?
I think I think I'll ignore that for now. Producer does all that stuff.
Don't we create a consumer as well?
Okay. So build an async Q async Q job system where one producer loads job and two work process and two workers process them simultaneously.
So worker okay and then worker named Hugh pulls a job and prints work process.
Wait. So, uh, Prince Hu job or Hu Job job_x.
How do you How do you like uh do that?
You know what? You know what? I think I got it. Uh, Claude did say me to not overthink it. So, I guess I'm not going to overthink it. I'm just going to go with something like worker.
We'll see what's the worst that can happen. The worst thing is that I'm just going to mess this question up. But well, I won't because I sort of do I am trying to get a gist of it, but just a tiny tad bit of just speaking of which uh we have a worker Q that pulls a job prints worker processing job_x and then waits one second. What the hell? So I'm going to go with something like while true. I want to go ahead and do something pulls a job. So while true I and prints that huh okay you know what I don't think it's a logic error here I think it's a syntaxual error I don't know my syntaxes for this part so I might throw plot here and then let's go ahead and paste it okay wait let me say something like since I do not think that I am struggling logically.
However, I am struggling syntaxually. Is that how you spell it?
Oh my gosh, guys. There is no way I spell that correctly. First try, I didn't. Okay, I'm struggling syntaxually.
Can you help me understand the syntax first?
Maybe by um some reference and then questions question mark. Okay. And then let's send it.
Okay. Good. Knowing where you are stuck is half battle. That's part of week.
Speaking of which, the worker syntax line by line. So we go with an async worker while true item equals to await hu.get.
How does that make sense? Suppose next job. Okay, so get wait if empty. What does get even do?
And then we print yada yada and then asyncios sleep one second simulate work and then print name done with items signal this job to finish.
Oh and then q.task done it keeps and keeps and keeps and keeps on iterating forever and ever.
Okay. And then main syntax. So we go ahead and run producer first. the Q of which okay launch workers so task one equals to async iocreate task I have work with create task it requires a cor routine my cor routine is my workers's um coroutine function and then task two is my worker B two workers dude before you continue uh you should learn type hinting at most it'll take 10 minutes and in exchange it will fix many syntax errors and make your code editor you smart. You will know what I mean once you use by typing. Do you mean like intlessons?
Cuz I might I might look into that after the stream. That's it. Wait, Q. join and then workers are stuck in while true.
And guys, let me know if the ads are balanced on the stream these days because many of you guys did the same me. They used to like overload it up.
That said, workers are stuck in while two. Cancel them. Task one. Task two.
Now, here's the thing. The cancel will give me an async io.canc error. I am so curious as to why did we not use or try and accept here.
Okay, two things that people trip up with. Q.task done. Await Q.task done.
No await. Oh, await Q do. join Q dot join okay I will be solving this question using the reference but then after this question I'm going to go ahead and work on question similar to this okay our producer of course it is it is correct like there was almost nothing that was wrong there and that's said in our while loop I'm going to go with item equals to await okay so I'm going to go with hue let's go with something like hue get now This pulls the next job waits if empty.
Okay. And then we're going to go ahead and print an F string that is going to go ahead and say something like here's the thing. I don't know how to access emojis.
So I'm just going to go ahead and paste this here. There we go. Okay. Cuz it looks much better with emojis.
Intlescence is a different thing. It will work better if you use type hinting. What does type hinting mean?
doesn't mean like when I'm typing something it just gives me like a bunch of options here cuz I might try that but I don't want these stuff that literally like gives me the entire code for the time being like when I type I remember when I first started working with like uh visual studio it did have copilot built in it so when I used to type anything for example like the main function it used to write my entire program based on the programs that I've already previously written that said let's go with await async kios I want to sleep for one second and then let's go ahead and print uh task done and yeah I'm going to just go ahead and copy my task done message because I don't really have the emoji here oh and I just realized one thing why is there a pair of square brackets here maybe it's a part of my syntax okay that's the item and then Next up, we'll go with something like Q.task done.
There we go. Okay. And then next up for our main function, the main syntax, we got to go ahead and await a producer.
So, I'm going to go with a another corine function for my main function that will not require any parameters, but I will be awaiting my producer.
And you know what? Let me get um add a hue parameter for this. Okay. And you guys know what? I might actually add a comment here that says run producer.
Okay. First fill the queue.
There we go. And yeah, I'm writing comments because I think that comments are like um really important later on.
This is just for me to understand what I'm working with. Next up the step number two that is going to be launch workers as tasks.
Launch workers as tasks.
Okay, perfect. Where I'm going to go ahead and create a task one. This is a part that I do know because I did work with this last stream. I'm going to go with something like async iocreate task that requires wait should it be await? Pretty sure it's going to be await.
Okay, so await async async io.create task that requires a code routine as a function which is going to be my worker which requires two parameters. a name.
I'm going to go with worker_a.
What are you doing? I'm working with Hughes. Actually, my current question, this topic is based on Hughes, but in general, I am working with async, IO, awake, and uh async. There we go. That name always confuses me. Okay, so we're going to go with Q. Next up, we're going to create a task two and await async io.
Uh, there we go. Dot create task that again requires a coine as a parameter which is going to be my worker. Now, this is going to be worker_b and the second parameter is going to be my hue. I spelled it wrong, didn't I?
There we go. Okay, perfect. And then next up, we wait until every item is task done.
We wait underscore every item is task done.
Wait until every item is task done. Interesting. So we go with q.join.
Okay. These are the bunch of methods that I haven't worked much with in general. And then workers are stuck in while true. Cancel them. That does make sense because we Let's be honest. There wasn't a break here. I was so confused.
Why wasn't there a break here? Okay, let's be let's go with number four.
Workers are stuck in while true.
Cancel them, bro. Trust me. Just put on a timer for 10 minutes and learn type hinting and use it everywhere. It will make your code much better. It's not tool. It's part of Python in itself. I might try that in that case. Okay. So, I'm going to go with task one.
A prop parenthesis and then task two.
Maybe like after this question I'm going to try that and then let's go with something like print all jobs complete.
There we go. And maybe maybe maybe since I have been going so precise here, I will be even adding the emoji here cuz there we go. The emoji looks a little good. And then lastly, let's go with if done name equals to equals to dunder mail. Then I want to go ahead and do something. I want to uh run my main function through my async io. Now let's hit control S to save the code. Control Alt N. Worker processing one, processing two, processing three, processing four, five, and six.
Nice.
Okay. Well, I guess let's go with control arr. Copy that. Okay. I might try type hinting here. Okay. Let's go ahead and paste it. Say um done.
However, I uh did copy the reference here. I definitely need more way more practice with the Q before we move on. That said, uh, someone from my chat told me to, okay, learn type learn type hinting to learn type hinting and that it would make my work so much easier. What is it? Question mark. Okay, let's see.
Uh, type painting. Basically, it reminds me of winter lessons for some reason.
I have three bugs.
Oh, okay. So, um, we await our Q.in. join.
But our create tasks are never awaited.
There we go.
Okay, now let's go into control 10. Wow.
Hey, two workers were done with the job so quick. That's fine.
There we go. Fix those four things. Oh, wow. Whoa, whoa, whoa, whoa, whoa.
Okay. And then also, your producer is missing a print statement for the requirements. So our producer needs for I in range one through seven.
Okay. I just want to see what this does here. I mean I do. Of course I know what it's going to do here. It's um shift.
Whoa.
Um hello.
Then there we have await u.put there. Okay. So for i in range await u.put job one print job one done. Yo where are you from? Let's let's go ahead and run this. Actually I am like from abroad. Q1 job.
Oh wow, it does a hell of jobs here.
What the hell?
Okay. Yeah, guys, I definitely need so much more practice with this. Let's paste it and then let's send it.
We're automating this.
Okay.
You know what? I think these syntax are finally getting to me now.
There.
Then let me go ahead and eat some more apples.
All right, guys.
Since when are Since when are apples with chewy?
That's a green code. It run once.
Question 16 done. Bank it. Now, typins.
That person gave you good advice, but here's the truth. Typins are phase one.
They're coming right after your async.io. You'll get future lessons when we get there. Don't jump ahead. Oh, so we're b Okay. So, basically our next topic is async.io. I mean is typens.
Okay.
Now, you said you need more practice with Q. I agree. You made three bugs on question 16. and needed the syntax reference that tells me Hugh hasn't clicked yet and the muscle memory level at the muscle memory level. So, here's the plan. Question 16 done. Question 17, Hue harder. Question 18, Hue harder.
Question 19 and 20, we introduce something new. You don't need to build a multi-agent AI system without understanding. You don't get to build a multi- aent AI system without understanding. Okay, Hughes. That's literally how agents pass tasks to each other. Two options.
Hit 17 right now. Hotter Hugh challenge.
You're tired. Stop. Here we come back.
Fresh me. Uh, option A.
I want it I um don't want it to be harder. I want to work on a few questions.
Okay. I want to work on a want to work on a few questions just so I get familiar with the syntaxes and then we can move on to a hard let's say harder questions.
Okay. And then let's send it. I might eat an apple as well.
M a restaurant order cube.
By the way, I see you're using Edge browser. Any reason why? Not judging, just curious. Actually, cuz I didn't really find a better browser. Like there are some people who said me to use Chrome rather than Edge, but then I'm like, as long as it gets the task done.
Which browser would you guys recommend I use?
That said, um, build an async Hue system where one writer takes order and one chef processes them. Requirements: Create an async io. Q. Waiter. Okay.
Create an async.io. Q. Vader puts four orders into the queue. Burger, pizza, pasta, and salad. Prince order taken.
Okay. Burger for chef. Prince order taken. burger for each chef with a hues parameter loops puts an order prints cooking burger waits 1 second prints ready burger calls task done I think with the uh hue dot join function or method in the main function uh run waiter first launch chef as a task with hujo jojoin cancel the chef Sprint all orders complete. I use Zen browser but of course everyone has their own opinions.
I see cuz I do want to definitely try different browsers but I don't really see a difference. Like do different browsers work differently or something because I'm like I basically only mostly um use browsers for either YouTube, either cake, Twitch, and all those different kind of platforms that I really work with and all that stuff.
Speaking of which, I'm going to delete everything. And since I'm going to be working with Async.io, I'm going to go ahead and import async.io.
And then it says that we got to create EQ. So I'm going to go with something like um Q equals to async io dot Q. There we go. So u equals to async io.q Q where I'm going to go ahead and create a coine function called waiter.
Okay. Now my waiter requires hu as a parameter inside my waiter puts four orders into hu burger pizza um pasta and salad four orders. So for every index in range I'm going to go with something like 1 through five because the last uh number is exclusive. is not included in it.
Okay. For every index in range 1 through five, wait, hold up. My bad, guys. Hold on a minute.
I'm going to go with hu.
There we go. We're not putting the same thing. We're putting a different thing.
I want to go ahead and put burger.
Okay. And then let's await this.
Okay. And then I'm going to go ahead and copy that. Two, three, four.
One, two, three, four. There we go. So, burger pizza.
Uh, wait. It's going to Oh, it's not it's not title case. So, it's going to be lowerase burger, lowercase pizza, lowerase pasta, and lowerase salad.
There we go. Print order taken burger.
Print order taken burger for each Zen browser is modern style. Not good. Oh, I see.
Okay. And then we're going to go here.
There we go. Okay, let's go with for a reindex in hue. Actually, in range one through five, I want to go ahead and print it.
Let's go with something like But here's the thing. Uh, if I were to look back at my previous codes as reference, we go with u.put put job underscore this thing job I this is the only thing that you need print job okay so I may not even need my range how am I going to go ahead and print order taken for each you know what I I don't think I'll need Okay, it might be a mistake that I made exactly in the previous question because I was like I'm not going to overthink that stuff. That said, chef hu loops for each. Next, we need two two coine functions.
Microsoft Edge leaves Windows browser with optimized performance across RAM, GPU, and CPU. It offers seamless Microsoft account syncing, robust workspace tools, and integrated copilot support. And that actually sounds really cool, guys. Let's let's go with something like chef, which requires skew as a parameter.
There we go. And then I'm going to go ahead and do something. Loops equals an order. Prince cooking burger.
We're going to go with while true. We're going to go ahead and do something here.
While true, I want to go with my Q dot.
It wasn't called pull, right?
Okay. Maybe good with Windows IDK though. I use Arch Linux. I see. Okay.
So, in the while loop, I wish I had a reference code somewhere.
Okay. So, while true, item equals to Oh, okay. Okay. So, while true, we're going to go with item equals to await Q.get.
This puts next job waits if empty. So, we go with P and then task done. Okay.
Once everything is done, our task is done.
So loops pulls an order and prints cooking burger. So cooking burger burger yada yada.
Okay. So we're going to go ahead and print cooking burger. Here's the thing. If my burger is being printed, second burger is ready. This is going to be an F string.
cooking item because this gets all my items.
Okay. For order in burger pizza await you do. Put order. You should learn to see uh patterns like this. Oh, I see.
Okay. I'm assuming that after the for every order in burger and the colon you go and indent the await you do. Like another line and it just didn't show it like that on chat.
Oh, but I I think I see for we order in burger and pizza.
Although I have pasta and salad as well.
Okay, let's see.
Wait one second then prints burger ready. So, we're going to go with await async io. I want to sleep for 1 second.
And then we're going to go ahead and print burger ready.
Let's go with something like ready burger. So, I'm going to go with an string.
There we go. Now, this burger is going to be my item.
Let's see in the main function. So, this is pretty much it for this. I'm pretty sure that I got to call task done. I forgot the syntaxes.
Item task. Nope.
Async io.task underscore done. Nope. Oh god, guys. I hate always looking up back to the references. I should just keep one open at all time.
Okay. Q q.task_one.
Okay, I see.
going to get my question back there. So, this is going to be my hue duck task done. Okay, perfect. And then next up, let's go ahead and create another C routine function called main.
In my main function, I will not require the parameters although we run waiter first.
We run our waiter first. Launch chef as a task with Q. Join. Oh.
Oh ho ho.
Okay. Okay. So in the main function we run waiter first. Run producer first.
Waiter is my producer.
So run producer first. I'm going to go with a weight waiter which requires hu as a parameter. Launch workers as task.
Okay. So we're going to launch chef second. So I'm going to go with task one equals to async io dot create task.
Okay, that is going to go ahead and require a parameter of um chef. What is the chef's name? So we go with Q and then cancel and then go with the ending.
Okay, let's see the chef's name unless there is no name. Okay, task done. Run waiter first. Launch chef as a task.
Chef_1, I guess.
Oh, wait. My bad. My bad. My bad. My bad. My bad. My bad. My bad.
And this is going to this requires a coine function which is going to be hue.
Okay. So chef as a task wait with hue do.join. Let's go with hu.join. This waits for my task done to be called.
Okay. And then print all orders complete. I got to cancel it. So, we're going to go with task one.
Because if we didn't cancel it, then it would be constantly running. Task one.
There.
There we go. I was like I was like, why is it not cancelling? Because our wild tree doesn't have a break. So, it's going to run endlessly until we did we did not really add this thing here.
Cancel. Then we're about to print something like all orders complete.
Okay. I mean, I did sort of need some reference here there. All orders complete. And then that's pretty much it. We're going to go with something like if dunger name equals C equals to let's say uh dunger main then is that tree underscores through my async ios is run method I want to go ahead and execute my main function control srl alt n we're going to wait okay nothing happens if dungeon name equals to equals to dungeon main. I'm pretty sure this wouldn't make a difference, but there we go.
Okay. Um, we have a join, we have a queue, we got that stuff, we got yada yada.
I have my waiter as a Q and then I've got task one.
Okay, maybe let's go with control C. Let me go ahead just grab clot up here.
Paste it and say I messed up dot dot dot. Then I'm going to maybe eat an apple.
Oh shoot.
There we go. Okay, there are some more mistakes. All order complete.
Okay, so let's read the hints again.
Look at your uh vader function. Your requirements is print order taken for each order your reader is silent.
Okay. How how though? For every index in range one through five cuz there are four orders range. We're going to go ahead and get our orders taken.
I mean, there is no item here. I'm not going to go with burger. Clearly not.
This should not be Q. I'm pretty positive this is not going to be Q, is it? Might go to the instructions up here. Y. Let's go down there.
Okay, we go with job at index of I. How will it know what is the I here? Wait Q.
How's the Goon game coming guys? Goon game is crazy. Although I am done with my programming for two 50day series. If you do if you guys actually do want access to the game, I have a community post. Matter of fact, let me show it to you guys real quick.
That's it. Uh, let me just go up there and then move on to YouTube. And then let's just grab cloud here real quick just so I can get this from my other window. There we go. Okay, in case you guys do want to try that game out, I I haven't really added it to my bio yet, but I will add it pretty soon. But for the time being, if you guys do want access to it, you guys can go to the post and move on to there we go. This the third community post down here. If you guys go to the comment section, there is a download link. If you guys click that link, it opens the game. It's called Collaborative 2. You guys can download it and then download the zip file, then like unpack it and play the.exe. It is pretty fun actually. It's not. Try reaching wave 100 then like send it to me on Discord.
That said, let's see. So, look at your waiter function. The requirement says print order taken burger. So, I'm assuming I do not really need any of that stuff. Rather, I just need my eye.
There.
There we go. Okay. So, Oh, shoot. I was kind of stupid right now. Since I was in that freaking link, I could have just copied it and added to my bio. Oh, god.
And that's I'm going to just go ahead and move on here. Let's see.
Um, or taken.
What up, guys? Am I joking?
Orders taken for each order.
Second hint. Uh, you made the exact same mistake in question 16. Oh, I did make that mistake in question 16.
We await this stuff and we do not.
There we go. Orders taken. This is this all orders complete.
We don't really have the cooking.
Orders taken. 1 2 3 4. I mean, it's I don't see no burgers and pizzas here.
I just see numbers because it's range because I use range.
H, let's see. I am going to go ahead and send it and I'll see an apple.
Yeah, it's a D.
Okay.
Oh, you're kidding me.
I thought that there was a way to do it without doing it manually, but I guess it's fine. Let's go with the weight.
Put I'm going to put burger.
And then we're going to go with a bunch of Ctrl Z's.
Going to copy this.
Then we're going to go with shift Z.
Then let's go ahead and paste this.
Okay. And this is not going to be an F string. So I'm going to close remove the F string from there. Rather this is going to say burger.
Okay. And then I'm going to go with await you.
Put I want to put pizza.
And then I'm going to go ahead and print this. You know what? I'm going to save some time. Going to save myself some time here.
Pizza.
And then we're going to go with another a hu.
I want to go ahead and put a pasta.
Hold up guys. I want to know the pronunciation. I think I'm pronouncing it wrong.
>> Pasta.
>> Pasta. There we go, guys. How old am I?
I can't even say that properly.
>> There we go. So, we have burger, we have pizza, we have guys, why does it feel so awkward to say in the right way? It's pasta. There we go. We have burger. We have pizza. We have pasta that I'm going to go ahead and print. Whoa.
There we go. This is going to be pasta.
And then we're going to go ahead and await our hue.put.
Why did everything just blink off? This is going to be salad.
Okay. And then we're going to go ahead and print.
Okay, I'm going to save some time here.
We're going to go ahead and print a salad.
Whoa.
Okay, this was manual, but let's be honest, this is this is the best that it gets.
Okay, so orders taken cooking burger.
Orders taken. Burger, pizza, pasta, salad, cooking burger, ready burger, cooking pizza, ready pizza, cooking pasta, ready pasta, cooking salad, ready salad. All is complete. Okay. I mean, I did get some health here, but I'm getting a gist of it, guys. I'm getting a gist of it. Now, speaking of gist, there we go. I'm going to say done. I am getting a gist of it now.
However, that just may be.
Okay. And then let's go ahead and send it real quick. And then I'm going to eat some apples.
There we go. All orders have been taken.
Look at line eight. Your chef is going to cook a bern. Nobody wants that. Fix it and paste the output.
Not the actual code. Okay.
Oh wow.
Let's go with control.
Okay. We're going to go ahead and copy that.
And then we're going to go ahead and trash that plot up here. And then we're going to go ahead and paste it and say here.
And then let's send it real quick. Then I'm going to eat some more apples.
Mhm.
All right, guys.
There we go. Why is the apple so chewy?
So test build an async Q where build an async Q where a dispatcher loads packages and delivers them. Requirements create an async io.q dispatcher Q puts five packages in pkj_1. I can use the range function here.
prints dispatch package one for each deliver cube loops pulls a package prints yada yada waits for one second prints yada yada task done in main function run dispatch with Q join cancel delivery okay all those basic stuff all right guys I know that I can use a range here.
So, we're going to go ahead and read the instructions real quick.
Oh god.
There. Now, since now, since we're going to be working with Async.io, I am going to go ahead and import async.io.
Can I got to make sure that this stream is still going? because I usually keep my device really close to me. But since I'm learning how to play Valentin right now, my monitor is really close to me.
My mouse is usually kept there and I'm locked in like this. But well, while I'm streaming, I am a little bit more open.
That's it. So the instruction says to create a hue. So I'm going to get the instructions a little bit bigger. Bit more bigger. Nice.
Okay, we're going to we're supposed to be creating a hue right now.
I'm going to set my hue equal to async io. What the hell?
Wait, hold on a damn minute.
Control R.
Let's refresh everything.
There we go.
And now my mouse moves fast as well. I'm like, is something glitch or is it just me?
The hell?
async io. Q. Why is it glitchy? There we go. The hell is wrong with this? Okay.
And then I'm going to create an aine function called dispatcher.
Okay, my dispatcher is going to be requiring Hugh as the parameter and puts five packages in pkj 1 through five.
Therefore, we're going to go for every index in range 1 through six. I want to go ahead and do something. I want to go with something like my hue do.put.
Let's go with something like an S string pkg underscore.
Let's say I. That is going to be one true six prints package dispatched for each. And I'm going to go ahead and print an F string call something like that.
Yeah, I want to I want to um be a little more precise with the emojis.
Therefore, we're going to go ahead and do that. And instead of one, I'm gonna go ahead and add I.
There we go. Okay. And what is wrong with this? Holy lag. There we go. I think cuz I need to apply that. Did that fix? Did that do the trick? Was it because of my OBS?
Wait, can I am I even Hello.
The hell? All right, guys. Let me refresh the stream real quick.
Maybe I'm going to close this. Open this. There already. Mic testing. Mic testing. There we go. I can finally see myself moving.
That's it. Hi, Nicole. I appreciate you joining the stream. We have you. Okay, guys. That's nice cuz for some reason in my OBS, I was not moving. I was like, what the hell? It's like, have I been yapping this whole time without you guys even being able to see it? I'm going to decrease some gain. There we go. All right, guys. I guess that's good. Maybe I want it to be a tad bit higher.
I may actually add my auto configurations here because sometimes my screen uh I mean sometimes webcam is too bright and sometime it's too dull. There we go. Now, where was I? I was going to create a package and read the instructions right there. So once we're done with creating our dispatchers Q, I'm going to guys you guys are sleepy or something.
That said, we're going to go ahead and create an async corine function called driver which is going to be requiring you as a parameter.
Write into async io. I see. Okay. Loops pulls a package and prints. So, we're going to go with something like while true. Why is it so glitchy? Like there's a whole.1 second delay after I type something.
Okay. Wait one second and print delivered package. Okay. So, we're going to go ahead and firstly print delivering package a number with your package.
Loops pulls a package.
I think I need to go with item equals to uh hue.get.
Guys, it's so laggy. What just happened all of a sudden? Okay, maybe you know what? You know what? I think I know what happened. We exit our Visual Studio and open it again. I mean, our Visual Studio Code.
There we go. Oh, wow. This is so much smoother. Yeah, guys, it was it was that was the issue all along.
And then we're going to go ahead and print let's say delivering a package.
We're going to go with something like an S string delivering package.
Although instead of package, this is going to be my item.
Okay. And then next up, we're going to go ahead and wait for one second. So, I'm going to go with a wait async io.
I'm going to sleep for 1 second.
And then we're going to go ahead and print a delivered package. Let's go with an string that says delivered package.
Yeah, I'm going to save myself even more time. This is going to be item.
Okay. And then next up, we call the task done. So, I'm going to go with hu.taskersore. task done. There we go.
Okay, I see. And then in our main function, so we're going to create another um async this horine function.
My bad.
Call the main which will not require any parameters. However, I will be running the dispatcher first. So dispatcher in this case is my producer.
I do not have a task yet. Maybe I don't need a task.
So, a weight dispatcher that requires Q as a parameter.
I'm thinking so hard if I needed a weight or not.
Okay.
launch driver as a task. So we're going to go ahead and create our task one for my async iocreate task which is going to be called task which is going to be called driver because we require a co- routine function that has Q as a parameter and then we're going to go ahead and wait with Q.in with Q.in. So, we're going to wait our q.join. We're going to wait for us. We're going to wait for our driver to return task done. Y takes hu as a parameter because well, I did create hue up here which was equal to our async io.q. I still need my notes for what hue really does because this is my third question and I'm still working with it. But as far as I mean whatchamacallit the thing that I know so far is that what Hugh actually does is we have a producer and a consumer. The producer loads in stuff and the consumer grabs that stuff out. That's basically all I know about it for the time being.
But the more questions I do, the better I'm probably going to get with this cuz dispatcher is our producer. It loads in all of our package. The driver is our consumer. It's using a while loop to get all our packages and deliver it. If that makes any sense. And once it's delivered all packages, it says task done.
And then basically in the main function, we just call our uh our producer. So it loads in everything. And then we create a task using the async io.create create task for our driver which is our consumer.
Our consumer which is my drivers routine function has a task to go ahead and uh let's say grab all the content that was loaded by my producer. My dispatch function once it's done it's going to go ahead and return a hue.task join. and we wait for our task join to actually send. That's what the join here really does. Okay. And then once it's sent, we go with let's see.
Okay. Once join is done, we go ahead and cancel our Q. So, I'm going to go with Q.Canc.
There we go. The reason we added cancel here is because our while true loop does not really have a break. So cancel manually cancels the cancels the whole thing. And then lastly, we're going to go ahead and print.
Let's say all packages delivered. I'm going to save myself some time. I could potentially type this stuff, but I don't have the emoji and I would have to copy that. That said, I'm going to go with if dunder name equals equals to dunder main. I'm going to go ahead and run my main function through my async io. Then we're going to hit control srl alt n. We run into an attribute error. Q has no attribute cancel. Of course, cn c e l.
Oh, wait. My bad. My bad. My bad. My bad. My bad. My bad. Task one. Whoops.
So, packages one, two, three. Dispatch, dispatch, dispatched.
We have one more error. Tiny one.
You know what? I think I'm pretty good with the syntaxes that I may know where I actually have the error. We do not We We await our Q. Our Q.
You know what? We don't await our Q.
We await our task underscore done.
No.
What is the expected output?
We wait for one second.
So we have our range. We put in the stuff. We display that stuff we have. Okay. This may be the only thing that might be wrong here.
Okay. So we are expected to Oh yeah, it is a core D function. You know what?
Let's go with control C. I'm going to copy that. I'm going to grab plot up here. Then let's go ahead and paste it and say I messed up again.
And then let's go ahead and send it. I'm going to eat an apple in the meanwhile.
Look carefully and see our put and get async io functions I mean hu functions they are Right.
You already know what's wrong. Look at your dispatcher and driver.
Same mistake twice.
Ask yourself are put and get a sync operation operations.
One word is missing in both lines.
You've written it correctly in every question before this.
There we go.
We needed a weight.
Oh god. Uh, need to learn where these awaits go.
Yeah, I still need to work on uh where these weights goes.
H, I see.
I think that I just do not have a nice understanding as to where the weights go and when all should I use them. I know that I must use weights when calling or routine functions or any async io methods in general.
Okay. And then let's go ahead and send it. Then I'm going to need something.
There we go. That's the output.
What up, guys? There we go.
Okay, perfect.
Queen. Perfect. Question 18. Now, let's fix your await confusion. We're good.
Here's the simple rule.
The await rule. One sentence. Await goes in front of anything that has to wait for something to happen.
That's it. Let's sink it in. Await q.put waits for waits if u is full. Await u.get.
Wait if you okay waits for time to pass.
Waits until all jobs are done.
Waits for co team function to finish.
Q.ask done. No wait fires instantly.
async io.create_task no wait just schedules no await the question to ask yourself every time you write a line ask does this line needs to pause and wait for something to happen yes await no await task done does not await it just flips a flag instant get might wait and the queue is empty if the queue is Empty not instant await that will carry you through 90% of cases tattooed in your brains.
You know what? I think I'm ready for harder ones then cuz believe it or not that question I didn't do it all by myself by reading the instructions. So I think besides that oh wait I got the gist of how stuff works. I think we can get the heat just up a notch.
Speaking of heat, new concept sentinel values. Oh wow. We're working with sentinel values now.
Right now you stop your workers by cancelling them. That's fine. But in production there's a cleaner way. A sentinel value. A secret signal that tells workers when done stop looping.
None is the sentinel. It means shut down. Await Q do. None. If item equals to oft dot get if item is none q dot task done then we break exit while two cleanly no cancel needed the worker exits itself gracefully. Question 19. Supports ticket Q with sentinel shutdown. Task build a support ticket system. When manager loads tickets, two agents process them tickets. Workers stop themselves using a sentinel value requirements. Manager Hugh puts six tickets. Tickets one through six prints when K through ticket six with print then puts two nons sentinels one per worker. Agent name Q loops pull tickets prints agent A handling ticket one waits a second prints agent A resolved ticket one calls task underscore done if item is not none calls task done and breaks no cancel and main workers stop themselves use async iogather instead of create task to launch both agents I have worked with gather which is kind of recalling that stuff expected output yada yada yada yada blah blah blah okay let's go ahead and uh get the instructions in the other window just so I can use them as a reference okay now we're going to go ahead and delete this since I'm going to be working with async IO I'm going to go ahead and include placing io. Then let's create a co routine function called manager that requires Q as a parameter. Going to use pass as a placeholder. While I go ahead and create a hue.
There we go. And then inside my sink.io.
Nice man. Okay. Inside my manager function, I'm going to put two tickets.
So, let's go with a for loop. Whoa.
Let's go with for every index in range.
There are six tickets, right? So, I'm going to go with one through seven because the last number in a range is exclusive. I'm going to go with something like ticket_1 through ticket_6 with print.
Okay. Then puts two nuns. Okay. Then puts two nons sentinel, one per worker.
Okay. Well, I guess put six tickets. So, I'm going to go with hu await because I am adding something here. This is going to be an F string.
That's C stick underscore I.
And then we're going to go ahead and Pence then puts two nons sentinel values, one per worker.
Pence then puts two nons sentinel values, one per worker. Non sentinel values, one per worker.
We have an await here.
We're going to go ahead and print an F string with prints. I might um go with the output here.
There we go. Just so I can get the sticker instead of this thing. Six.
uh ticket I okay now how do I do the none parts so then puts two non sentinel values per worker how you do that you know what you know what you know what I I think I think let's think about that later I'm going to go with a second corine function called agent that requires name as a parameter and my hue as a parameter where loops we're going to use a while loop loops pulls ticket prints a agent handling ticket one.
So we're going to go with we're going to pull a ticket. So, I'm going to go with item equals to await Q dot get. I'm going to go ahead and get my ticket.
And then um I'm going to go ahead and print an F string that says something like agent handling ticket yada yada.
Oh god, this is so tedious.
instead rather than having ticket one, I'm going to have item.
Okay, there. And then next up, uh once we're done with that stuff, we're going to go ahead and wait for 1 second.
Therefore, I'm going to go with async io. 1 second. And since sleep uh has a timer, I'm going to go ahead and add a await so I can wait for my sleep to be done and run other uh chunks of code while my sleep is still working or while my sleep is still in progress.
And then print agent resolve ticket one. I'm going to again copy that stuff just to the emojis. Here's the thing. I can type these things, but then since I need to actually add emojis, I'm like, it's going to be so much easier if I just copy the print statement.
Okay. And then call task done. Task done require a weight. Therefore, I'm going to go with task done.
My task is just done. That's it.
If item is none, call task done then break.
All right. How is my item going to be none?
Something like this.
Q.put to none.
Okay. So, at least once once everything here is done, those seven my is going to be set back to none. Oh.
Oh, okay. Let's go with something like if item is not none.
Q dot uh task done.
There we go. Okay. And then we're going to go ahead and break.
And that's actually pretty much it, right? No cancel the main function. So let's create our main function or our main C routine function now that is going to go ahead and workers stop themselves. So first I'm going to go ahead and call my managers is Hugh. Let's go with manager Hugh.
I call my managers as Hugh which in turn gives me uh or loads all my tickets in that is my producer. It gives me the content. Now time for my consumer which is my agent who is going to go ahead and do my stuff for me. I'm going to create a task for my let's go with async io.create task. I'm going to create a task for my agent function.
You know what? Let's name him Alex. And then the hue is going to be my hue.
Well, there we go.
Now that we have a test, I'm not going to go ahead and break anything or cancel anything because we already have a break. However, I will be using gather use async io. Gather rather than async.io.create dashboard. Okay. To launch both agents.
to launch both agents. Wait, both agents.
All right, here's the thing. I just have one agent. Unless he's unless Claude is talking about the manager as an agent as well. I might do that.
Okay, let's go with async.
await async io.gatherather.
I want to go ahead and gather my manager that requires hu as a parameter and I want to go ahead and gather my agent that requires a name that is going to be Alex and a hu as a parameter.
Okay. And then launch both agents. I did do that stuff. Now I'm going to go with if dunger name equals to equals to dunger main. I'm going to go ahead and through my async ios is um run method.
I'm going to go ahead and run my main function tickets one two three ticket one handle.
All right we just have our first ticket handle. Maybe on my for loop hands to get one handle. Oh wow. We're just having our ticket one handle here.
You know what? Let's let's copy that stuff up. I'm going to drag plot up here. Let's go ahead and paste it and say h I believe that I messed up again.
Interesting. Let's go ahead and set it real quick. What the hell? How did I manage to mess it up again? Like all the questions that I've done till now had a tiny bit of errors. I see four mistakes.
What the hell?
Tell me exactly where. Look at your code. I see four mistakes. How can you spot before I reveal them?
Four mistakes.
Definitely the first mistake if item is dumb.
That's not a mistake. That is the second mistake. There is no typos anywhere.
Um uh Q ticket_1 while Okay. Okay. Okay. So hu.get I made sure that was correct. And then we have put made sure that was correct.
Okay. I think it's the mistakes for the newer logic or the newer syntaxes.
Okay. Let me go here.
I think that my none was uh the place where I did make mistakes and then let's send it real quick. Go here. Let's delete that. There we go.
Okay, I guess there's thinking good instincts. Yes, a none is part of it, but here's the three actual places.
Where should the sentinel go?
Mistake two, none versus none.
Oh, you're kidding me. And one mistake outside of none entirely. Look at your agent function.
You have a name parameter.
Oh, guys, how how there is no freaking way I use none. Right, right, right, right, right, right, right. Oh my gosh, guys. This is the kind of mistakes that I hate doing. What the hell?
We have a none and then look at it carefully. You have a name parameter.
Oh, this is going to be my name in a pair of curly braces.
Same is going to go with this.
There we go. Okay. So, we've got our name parameters here and then we have our task done. We have a bridge. We have a queue.
Nothing else is wrong, right? Let's run.
Alex handling ticket one. Alex resolves ticket one. Now, we got to go with ticket two and three. Now the second thing is where do you think the sentinel value should go once all four are done.
Okay. I actually think that the sentinel value must go there.
Okay. And then yo hiding pixels appreciate you joining the streams.
Mistake two. None versus none. Mistake three. How many workers do you have? How many sentinel values do you need?
This is one per loop. One sentinel value per loop. I did fix majority of them. Um believe I fixed majority of the issues.
Why did I add a question mark? I'm sure I fixed majority, but I did not fix the newer syntaxes.
H, you fixed none and name variables.
Good, but three mistakes still remain.
This puts none after every single ticket sent to the value goes after the loop. I did try it after the loop. Mistake two.
Your if uh /break logic is backwards.
You break when item is a real ticket.
If item Oh my gosh, guys. I just It's Do I even know my syntaxes at this point?
To get one, get two, get three, get three, and then get four.
Get one result. Get two result. Three result. Four result. Five. Six result.
Alex resolve none. Okay. Now when the last part does execute, I want to go ahead and just display my main stuff.
Okay. What was the final thing that I had to display when everything is done?
All tickets resolved. I got to go ahead and print all tickets resolved. So the final error which is going to be here.
One agent needs two.
Two workers means two sentinels in gather.
Okay. So, we have agent one. Let's add a second agent.
This is going to be called uh Hannah.
That is going to be called Nova.
In case you guys did watch my uh programming series, you guys would know who they are. My programming for 250day series. I mean, and then all tickets resolved. So, we need to add all tickets resolved as well.
Okay. So, once this is the case, we're going to print all tickets resolved.
Okay.
Noah had wait. Noah had ticket one.
Hannah had two. Noah had one.
Oh. Oh. Oh.
No resolve. None.
No one handling. None. Noah resolve.
None.
Item is my hue.
Okay, I mean it does work. It does work.
Now, let me just go ahead and paste it and say it does work now.
However, I do get a small um issue.
When my program ends, the output says nova handles none and nova resolves none.
Then let's send it.
Good progress. But two things. You still have one sentinel for two workers.
How does that change a thing?
Your code prints handling none before checking.
Why do we need that? Oh god.
We need a task underscore done if it's none. We need a task underscore done once we're done.
We have two workers. So we need two nuns.
The only part that I didn't understand.
And then apparently we don't need this here. I will be copying this print statement. Why not?
And then we we create our item here.
Before we print this stuff, I want to check if my item is none.
I want to go ahead and initiate my hu task done.
And then we break else we print that stuff and then in the main function we're going to go ahead and print that case everything is over.
Noah handling ticket one resolved.
Handling resolved. All tickets resolved.
Perfect.
Okay, let's copy that. Let's go ahead and How is happening? You mean like how's it going? It's actually going pretty good. I'm starting to get a gist of it. Let me say something like word.
And guys, um an hour and 30 minutes in the stream and I'm still like it's starting to get a gist of it. I said that like 13 minutes on stream as well or something like that.
That's sad thinking. Let's go. Question 19 done. One small thing to note though, you're missing task done should be here too. Okay. Why?
Okay. Now, here's the question. Let me run this real quick. Noah handling ticket one. Noah resolved and absolved.
It seems like today was very busy.
Honestly, I mean, I won't say as busy, but uh it is it is it is it is kind of decent here.
Okay, Q progress check. Okay, here here's the thing.
I had uh two questions though.
Why did we need a two sentinel values?
Like will it ever make a difference? Cuz I basically added the same line twice.
Await Q dot put none.
H.
How does it change something? Um, if I just did it once since it is not assigned to a variable and it's just like a statement. If that made any sense, will it not override itself?
And secondly, why did we need a task underscore done after the print statement and also after the if check.
Oh god, guys, my typos are so bad here.
That's it. I'm going to go ahead and send this.
Have you used claude code CLI? Is that like a free Is that like a free version?
because I have been only using the freer versions here. I'm currently using the latest free version which is the net 4.6 with adaptive thinking. That said, question one, why two sentinels? Think of Q like a physical line of items.
Ticket one, ticket two, ticket three, ticket four, ticket five, ticket six.
None. None.
Each worker pulls one item. So Nova pulls ticket one. Hannah pulls ticket two. Nova pulls ticket three. Hannah pulls none. Noah sees none breaks Hannah pulls. Oh, I see. I see. I see. I see. I see. Question two. Why two task underscore done calls? Simple rule.
Every get needs exactly one task underscore done. You call get once regardless of what you pulled. Real ticket or none. The you registered that you took something. You must tell it you're done with it. I see.
Well, ticket path item equals to await u.get took something do some work. Q.ask done. So here we're done with it.
Nonpath item equals to do still needs to tell you get equals picking a package. Task done equals to signing the receipt.
I see both clear.
But let's go with something like however I do need uh some time to soak the info.
Therefore uh maybe actually you know what you know what ready. I was going to sell watch tutorials but I think I got it. I don't fully got it but yeah new concept priority hues. So right now your hue processes items in order first in first out but what if some jobs are more urgent than others? Async io.priority hue processes the lowest number first. Q equals to async io.p priority u await hu.put one urgent task priority one first out await hu.put Put three low task priority three last out. Okay. Item equals J.get.
Okay. You know what? Hospital emergency.
We do that stuff. Blah blah blah. Bob, Alice, Charlie, Dena, Eve.
Okay.
Actually, you know what? Yeah, let's let's do it. Let's do it.
Use async.io. Priority nurse.
That requires two parameters. Okay.
What has a perforen parenthesis in it?
Nurse Hugh adds five patients as tpples.
Okay. For each then puts two nons sentinels as zero none. Priority zero.
They come out last. Wait, what will work? Think about it. Doctor name and Hugh pulls patients unpacks tpples.
Checks for none. Prince Dr. Smith treating name waits one second print Dr. Smith done with name calls task done two doctors launched with gather prints all patients treated. All right, you know what? I'm going to go ahead and get the instructions in the order window.
Hospital emergency Q. Build a hospital try age system. Patients arrive with different urgency levels. The doctor always treats the most critical patients first.
Okay. Well, I guess we're going to go ahead and delete this. And since I'm working with Asyncio, I'm going to go ahead and import async.io. Then we're going to go ahead and create a hue called async io. priority hue.
There we go. And then we're going to go ahead and define a um corine function called nurse.
that requires a hu as its parameter and then now inside my parameter adds five patients as couples prints patient register patients's name five patients as parameters I mean five patient parameters as couples doesn't I'm assuming this is how it goes Denver five patient patients as tpples.
So a tpple mean a list of patients and a tpple just tpples.
Um you know what? Let's go with await Q.put. I'm going to go ahead and put my first patient. I think this is the double urgency is going to be one. This is going to be urgent test.
Okay. And then we're going to go with our second tpple which is which is going to go ahead and be another weight.
But we can iterate over this stuff, right? So I might remove that. Might remove that. Might go back here. And I might go back here. That's out.
Q.put.
This second patient is going to be at a priority of three. It's going to say low task. So low test.
Okay. And then we're going to go with something like await Q.put. I'm going to go ahead and put my third patient at a priority of two.
Medium task.
Or let's go with normal task. Same thing.
And I just realized let me go ahead and lowerase my urgent as well.
There we go. Okay. And then once we're done with that, ying pixel, appreciate you enjoying the stream. Okay. We're going to go with item equals to away unpacks the tpple.
Okay. Okay. Now in the instructions adds five patients to the tpples. Okay. So we have patient one, patient two, patient three.
Okay.
For each then puts two nons sentinels as zero and none.
I'm thinking this so hard right now.
Priority zero. So they come out last.
Wait, will that work? Think about it.
Priority zero. They come out last. It does work.
doctor name and then this is pulsation and backy okay and then we go with sentinel yada yada okay wait let's go with four and five you What? Patient one. This is going to be patient one.
That is patient one. And then I'm going to go ahead and copy that. That is patient two. That is patient three.
There we go. And then this is going to be patient four.
Patient four. And lastly, we're going to go with patient five.
That is my patient five, which has a priority of five.
45. There we go. Okay. Now, we're going to go ahead and add two nons sentinels.
So, I'm going to go with await Q.put. I want to go ahead and put this as priority zero.
none. And then we're going to go with another await Q.put.
This is going to be priority zero of none. They both execute at the very end.
I'm trying to get what none means to be honest. Speaking of which, patient registered. Then we go with patient registered. Our patients name. I'm positive this is the thing that goes manually. priority and oh god why is my I increased my DPI because I'm trying to grind a little on valent so my mouse moves way too fast but I'm getting kind of used to it said let's go ahead and print string paste whoops there so patient registered this is just going to be a regular print statement.
Patient's name is going to be patient. You know what? Screw it.
Alex. I like the name for some reason.
Alex has a priority of one.
And then I'm going to go ahead and save me a whole lot of time by copying this, pasting it here.
This is going to be called Hannah. My second patient is Hannah.
Hannah has a priority of three, not really as important.
And then we're going to go ahead and copy that. I'm going to go ahead and paste it here. My third patient is going to be called Bob.
Let's go with the Bob has a priority of two.
And then let's go ahead and copy this.
I'm going to go ahead and paste it here.
My fourth patient is going to be called Sarah.
Sarah has Whoops. Let's go ahead and change that to Sarah. Sarah has a priority of four. Lastly, for my fifth patient, I'm going to go ahead and register it and call it something like um I don't know. What should I go with? Um, pixel. There we go, guys. I can't think of a better name. Okay, let's go with something like pixel. Pixel has a priority of let's say something like five. Okay, perfect. And then next up, once we're done with this, we're going to go ahead and create another async iioses quarantine function. So I'm going to go with something like async define. Let's name this to something like doctor that requires name as a parameter and Q as a parameter where I'm going to go ahead and pull patients. So we're going to go with while true.
I'm going to do something. I want to go ahead and pull my patients from my Q unpacks couples checks for none. While true, I'm going to go ahead and set item equals to my hue.get await hue.get.
Okay. And then, excuse me guys, checks for none.
If item is none, then I want to go ahead and do something. I want to set my q.task done.
Stop the task. Break the loop.
And if that did not really happen, I'm going to do my regular chores, which is basically going to be me printing Dr. Smith treating name. We wait for a second. Okay, I'm going to go with something like print. And yeah, just to save some time, we're going to go ahead and copy that stuff.
There we go. And then I'm going to set this to be an F string. Paste it in that colon. And rather than saying doctor is a myth, we're going to go with our name tweeting our patients's name, which is going to be my item.
Okay. And then we're going to go ahead and let's say wait for a second. So I'm going to go with a wait async io without sleep. I want to sleep for 1 second which means the core t function is going to be paused for a second. Then we print something like another string.
Okay, my string is going to say Dr. Smith done with test.
There we go.
And again, it's not really going to be called Dr. Smith. Well, it depends. I could call it Dr. Smith, but it's going to be my name and this is going to be my item.
Okay, perfect. And then we call our task done. So we go with our q.task done. Okay, now two doctors launched with gather function. So this is where we go ahead and call our main function.
I'm going to go with async define a main quarantine function which is going to go ahead and let's await my hue gather. I want to go ahead and gather a bunch of my functions. The first is going to be my nurse function which requires Q as its parameter. The second is going to be my doctor function or my doctor's score routine function that requires a name.
You know what? Dr. Smith is nice.
Okay. And then it requires a hu parameter.
And then lastly, my third thing could be another doctor because I need two doctors.
Okay, two doctors uh with my gather.
What should the second doctor's name be?
So, we have a Dr. Smith and then we could go with something like a doctor um what doctor, guys, I'm bad at naming.
Should I pick a random name from chat?
Uh oh. Wow, Dr. Med sounds nice. Dr. Med.
There we go. who is um going to be having hu as a parameter as well. And then lastly, we're going to go ahead and print a regular print statement that's going to go ahead and say all patients treated.
And let's paste it here. Okay. And then lastly, I'm going to go ahead and add something like if dunger name equals to equals to let's say dunder main. I want to go ahead and through my async io run my main function. Okay. And then let's hit control srl alt n. Oh wow, we ran into an attribute error. No attribute gather. I spelled gather wrong, didn't I?
My bad.
There we go. Patients registered doctor. Oh god, this is going so fast.
Let's let let all patients get regretted real quick.
Okay, they're done with all patients, but we did not really get our print statement up here.
Let's try again. Okay, so patient registered. So we have Alex, we have Hannah, we have Bob, we have Sarah.
Doctor treating zero, none.
It goes with the lowest priority.
Wait, would that work? No, no, no, no, no. If my priority is set to zero, it will not work. So we got to go with six.
Alex gets treated first. Bob's gets treated first and then we have Oh my gosh, what the hell?
No, we can't. We cannot have priorities.
Maybe this is just going to be a nonuple there.
Um, we cannot not have a double Interesting. And then this doesn't get c this does not get called as well.
Okay, maybe I guess I'm going to go with control or control C. Let's copy that.
Let's get a wrap plot up here real quick. And then we're going to go ahead and paste and say h I messed up.
Okay. And then let's go ahead and set it. Guys, the the casual messing up stuff. What the hell?
Okay, so we're I guess we're thinking got all day. Okay, good instinct catching it yourself. I mean, I did get an error. So, u0 none priority zero. Think one sent remember lowest number comes out first.
That does make sense.
Think about the none check. Can a tpple ever equal none? I don't know. Can it?
You're unpacking in your print but not before your check. What should you do for what should you do first after get?
So uh if item is not none, I mean adding it to a six wouldn't really help it.
I mean it will help it. That's literally what helps it.
Okay, wait. Let me just go ahead and grab this back up here. Let's say I mean I added my uh usees none to have a priority of six. But what goes after get?
And can a tpple never return none?
Cuz that may be a reason. That actually might be a reason.
Could uh fix on the sentinel priority six is never none.
A tuple can never equal none. Your check will never trigger.
I did not know we could do this stuff.
You need to unpack first.
Priority name equals to this. Now you're checking the actual value. If name is none, Q.task.
Of course, of course, of course, of course.
Also fix fix your print statements.
Right now you're printing the whole tpple.
Right now you're printing the whole tpple for every priority.
Okay. I did not know we could do this part. So I kind of I kind of just blame the situation in this place or my lack of understanding here. If name is none here which just breaks off and then this is going to be my my name. My name I just realized we can't really call that our name. This is going to be doctor name.
There we go.
Yeah, because I can't really have the name as my name. This is going to be doctor name. That is going to be doctor name.
Control S and let's go with control al.
Now first let's read this a little bit slow. So patient registered, Hannah registered, Bob registered, Sarah registered, Alex registered, Pixels registered, Dr. Smith is treating Alex. Dr. Med is treating Bob. Dr. Smith. Done with Alex.
Dr. Smith treating Hannah.
Dr. Mad. Done. Done. Done. One, two, three, four, five. One, two, three, four, five. All patients treated.
Perfect.
Okay, that was that was a little bit tricky at first, but it's not really that hard. Ah, I see.
So, it was just a syntax error because I did not know that we could do priority name.
Okay, that's it. Let's go ahead and send this real quick.
Okay, it runs 20. And yes, that's the that's called tpple unpacking. It's not async specific. It's a core python.
Guys, am I just stupid? Then you can do this. It's the same thing. So item equals to 6. Priority equals to item index of zero. Name equals to item at index of one. You can do this same thing in one line.
Priority name item at index Oh.
Oh. Now look at your output versus expected output. The difference expected no brackets. It's fine.
Okay, that said, uh I will probably work on questions 21 through 30 next stream because uh I do need to go right now. Okay. Uh, that said, can I get the prompts for the other chat? Okay, while I'm actually doing this stuff, I'm going to go ahead and let's say move on to my main camera. And guys, what the hell?
Come on. The one time I move my eyes off my um webcam, it starts to get all shiny and all that stuff. Okay, I'm going to decrease my exposure just a tad bit.
Wow, that's a lot.
There we go. That's perfect. Okay. And then let's go ahead and click okay. All righty, guys. So, basically, that was pretty much it for the stream. I am going to be working on days 21. I mean, what's not days 21, questions 21 all the way to questions 30 on my next stream.
And today, hopefully, if I'm not fully as lazy, I will be working on completing all my review montages. All these days I have been grinding a little on Balance.
So when I start streaming I can actually be really good in it and I am starting to uh get a pretty good grasp of it.
That said, if you guys uh did enjoy the stream, don't forget to smash that like button, subscribe with the notifications bell, turn on and also share this video because liking my algorithm. Sharing makes you smile, subscribe to the share on top. That's it. I will start streaming on Twitch and take once I get a graphics card which I will be getting sooner and I will start streaming on Instagram and Tik Tok as well if I did meet the followers requirement. So if you guys do enjoy my content and haven't follow me there make sure to follow me there. The link is going to be description the link is going to be the bio. You guys can get access to any of my socials in general if you guys type exclamation and the socials is name on chat everything lowerase. If these socials does exist, a link is going to pop up in like about two to three seconds. If it does not exist, the link will not pop up. That said, also make sure to join my Discord server. That's where I usually talk to you guys, chat with you guys, have general conversations 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 social. Actually, you guys can get access to my Discord server by typing exclamation discord on chat through the link in the description through my bio. And yeah, I think that's pretty much it. That's where I mean my discord server is usually where I talk to you guys, chat with you guys, have general conversations with you guys as well. And if you guys do want to join uh or whatchamacallit go along with me in this AI engineering for 365day series and you guys do want the road map that I am using for this you guys could go to my coding helps chat or my Python chat and mention my name there at web universe and ask me for the road map. I will be personally DMing it to you guys.
That said, I'll catch you guys next time or video. Peace.
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











