24:45 why doesn't it print the return statement {'data' : 1} ?
It was very useful thanks dude
So for a robot's tasks going to the toilet: if dont await the crapping process he would flush too early, right?
Nice video!
25mins just passed liked that. so well explained.
thanks
AT FIRST I DIDN'T UNDERSTOOD BUT THE 2ND TIME IT WAS SO CLEAR! THANK YOU!!!!
THANK YOUU
Great Video, but can we do paginated api calls with asyncio?
nice tutorial ,tho not comprehensive . We actually need real life use cases.
Thank you for making the awesome video
you gave the crux of the async
now i can finally learn FASTAPI
thanks a ton buddy
16:40 The program is halting prematurely. foo() needs to be awaited - you did not allow it to complete the 10 second job.
Can i make multitasks and multithreading work toghether? like making multiple requests to a server or something like that?
Great video. Thanks so much, very helpful.
This is a bad example - it all goes horribly wrong where you await task1 and task2. Obviously you have no idea which of those tasks will finish first but you fell back to blocking code with an expectation that task1 will finish first. Not your fault - Python async/await code is fine, but the equally important higher-level syntax where you create co-routines and selectively await results is a poorly designed set of asyncio class methods which have changed with each new release of Python (and changed again in 3.8 after this video)
So clear about all informatiion. Tnx!
Man it ain't much asynchronous, it is still running only one thing at a time! By asynchronous programming, we should be able to run multiple tasks at a single time.
Awesome!
Excellent tutorial, thanks.
great video tim, I am a Typescript developer but I use python too. I was wondering if handling errors with Futures is like handler errors with promises in Typescript
Hello! I have a very small programming channel, I was wondering if you had any tips for me? Thank you!
I have a question at 7:57 that how the function task runs only in half away while it is not executed by using await keyword?
THANK YOU! VERY CLEAR EXAMPLE😁
You are a lion👏😁😁
that is a very informative video wow
Even though I watched a lot of videos and read a lot of articles about asynchronous, I did not understand the mean idea of asynchronous until I watched the very first four minutes of your video. Great explanation! Thank you!
flori hmmmmmmmm, shiptar koka , e di une, sigg ,qin qin XD
Perfect video - definitely the easiest to follow explanation of this topic that I've seen so far. Thanks!
Thx man it was very clear!
Multithreading also does one thing at a time. It is also does the thing concurrently
Wow, it is an amazing content. Thank you. I would like to know more about asyncio in Python. How did you learn it? Do you recommend some lecture or article?
at10:20 u could also just use f"{return_value = }"
terrible video
Saved my day, thanks.
Thank u very much man. Helped a lot. U explained it in a very elaborate and understandable way.
This is the best explanation about async/wait in Python, thank you buddy!
This is a crystal clear explanation with the easiest examples. I have watched a few clips before this about the same topic, but I could only get a vague idea about this concept. Now, I think I can use this for my code. Much appreciated.
Easily explained with efficiency. Thanks man !!
Nice balance of explanation and elaboration, much appreciated!
Nicely explained. I watched other videos on same topic. But I got the real subject from this video only. Well understood difference between thread and asyncio.
This is easily the best intro to asyncio python tutorial in YouTube. It gives you essentials for you to develop on that basis. I think after this short introduction you can get to at least high level elements described on official documentation with not much of difficulties. For beginners: on the challenge two he asked for a countdown from 10 to 1 and not from 0 to 9 as he performed. The way to do this you have to specify a step in range function: it would be for i in range(10, 0, -1): (...).
Wow, it is an amazing content. Thank you. I would like to know more about asyncio in Python. How did you learn it? Do you recommend some lecture or article?
Thanks a lot for clarifying this! Awesome
does await freeze the UI? for example with tkinter?
import asyncio
async def fetch_data():
# await asyncio.sleep(5)
return {"data":100}
async def countdwn_num():
for i in range(10,0,-1):
await asyncio.sleep(2)
print(i)
if i ==5:
x=await fetch_data()
print(x)
else:
continue
# async def data():
# x=await fetch_data()
# print(x)
async def count():
await countdwn_num()
async def main():
# x1=asyncio.create_task(data())
y1=asyncio.create_task(count())
# asyncio.gather(x1, y1)
await y1
# await x1
asyncio.run(main())
# countdwn_num()
x=await fetch_data()
print(x)
i think this code can be optimised ..!! have a look Mate
very good explanation! thank you !
you are a very good teacher .... i struggled to understand asyncio ... but you just have simplified the concept to my understanding with the examples.
Best tutorial on this subject. Keep it up :)
First I like than watch. Thanks
why didn't the second reply came back at 5.11 , looking at the console both first and third email reply was there, which awaited for 2 seconds. The second email had awaited for 5 seconds but the output was not printed. Please clarify this.
par excellence
Does create task method run these routines in separate thread
( And what are the different use case scenarios for asyncio than threads if routines run in separate threads)
Zander absolute beauty is what can say to your video and content. Just brilliant
Please, in the beginning of a video, please also introduce these new terms - what are they and where they are used...
We are too noob to understand it from the beginning.....
I followed your django + react tutorial but got stuck once where you have introduced material ui.
What was that thing ? Took me 1 more week to recatch the same video..again..
neat
OMG. I tried to learn the same topic couple of weeks ago and it was like learning a new language. This is such a nice explanation. Thanks Zander
Please make a video on threading
How to use asyncio to handle multpile tcp server sockets? Will asyncio handle multiple tcp server sockets better than threads do?
Cool
lock = threading.RLock() did not solve the problem here...
5:50 await: go to another coroutine
i have an assumption about: what if asyncio.sleep is another function that make a processing of something, and as we already know asyncio is a single process, single thread, So how the event loop behaves on such case? does this processing function be a blocking one? or what?
"These coroutines are an abstraction on top of event loops. That's pretty nice so you don't have to think about all these callbacks, because otherwise you would end up with very ugly code." -- a former JS developer
Async and Parellel... Mixing statement, not quite correct !
so in order to run asyncio with blocking code you need to block asyncio... basically nullifying it's purpose.
If I get it right, asyncio has nothing to do with parallelism. It is still only one thread switching between "events".
Why bother comparing it to multithreading (-processing) then?
The whole point of asyncio in Python is to have one and only one thread run an event loop. In this loop tasks will be switched at well-defined moments, that is, when the programmer writes 'await'. So you're doing cooperative multitasking like in Windows 3.1, with the difference that it's not the Windows task scheduler deciding when to switch tasks [during GetMessage()], but you yourself, depending on your await signals.
What's the point of all this? Well, you can do asynchronous io, e.g. with sockets. The behind the scene code is written in C and uses a real thread pool. As this thread code runs outside of Python, it is not hampered by the GIL and will run in true parallel fashion. So while one coroutine is downloading data from the internet, another coroutine can run truely parallel.
Now modern sockets have an asynchronous mode themselves and you can utilize that option in standard Python code. It is more work, but you will not be limited by this all dominating event loop.
Now, if you want to load and process a big batch of huge files from your local hard disk, you want asynchronous file read. This is okay in Linux, but for Windows you need io completion ports (iocp) for the file system. They exist, and use an internal system thread pool behind the scenes. As these are not Python threads, you are once more not hindered by the GIL.
UNFORTUNATELY Windows file iocp is not implemented in Python, so asyncio is of no help for files. The reason is that it is difficult to get right, because Windows will switch to synchronous mode automatically when the file is small. However, it IS implemented in C#. Python core developers should look at the C# internals. All of this is less of a problem nowadays with ssd drives.
Asyncio is pretty useless for cpu intensive tasks, unless you either employ subprocesses or worker threads that delegate to a C library that uses parallel threads behind the scenes. Otherwise the GIL kicks in.
I think this guy is from France
Async/await nation
I still find it really tough to use async/await in python unless the IO operation itself supports asyncio. Nearly everything in python is blocking. I know there are still ways around this but that just means so much more boilerplate code.
I'm not a python async io expert but this guy is mixing parallelism with concurrency. This things are not the same. The comments about Async.gather makes me believe he doesn't understand the topic. I haven't tested it but if you ran two async functions that call thread.sleep(1), async.gather would respond in 2 seconds, not 1. I'm aware that he said not to use "blocking code", but that is exactly the reason why it would block the event loop. Pararelism != Concurrency/asynchronous