Learn Python's AsyncIO in 15 minutes

preview_player
Показать описание
In this tutorial we will be looking at asyncio, which is a package from the standard Python library which allows us to do asyncronous programming. It's very easy to learn, but can be a bit tricky to master. Any way, we will be covering how to use it in less than 15 minutes!

▶ Become job-ready with Python:

▶ Follow me on Instagram:

Documentation:
Рекомендации по теме
Комментарии
Автор

Simple but most essential and elegant explanations for the asyncio. Huge thanks!

WDieSmile
Автор

1:44 I think the point of 'await' is to let python do a context switch. Normal function call to sleep will also transfer control to the next line after the sleep is done, await doesn't affect that

eitantal
Автор

Thanks for the content. I think there are a few ways to do this, In the example you execute the function and then append the returned data to the list, rather than appending the function call itself to a list, Here are 2 examples:
tasks = for i in range(1, 10+1)]


await asyncio.wait(tasks)
for task in tasks:
print(task.result())

or

list_of = []
for i in range(1, 10+1):
task =
list_of.append(task)

await asyncio.gather(*list_of)

djbroake
Автор

11:10 the asyncio.sleep can be set to asyncio.sleep(0.0) and it will stil register
i know its a bit late but still might be relevant..

YoKKJoni
Автор

The `await asyncio.sleep(0.5)` isn't needed because "the task sometimes happends so fast that task.canceled is not going to be able to register the cancel in enough time"! But it's needed because `task.cancel()` doesn't actually start the cancelation but merely schedule it for cancellation. The task will be cancelled when control returns to the event loop, which happens when an await expression is encountered.

ramima
Автор

I think this video is great. Very clear.

cusematt
Автор

Thanks o this video I've decided to rewrite my synchronous data grabber (web scrapping and directly via API) based on requests to asyncio and aiohttp. Speedup was about ~2x :)

grzegorzryznar
Автор

This is arguably the best asyncio-await explanation on youtube!. thanks for keeping it simple to understand!

hillolbro
Автор

doesnt await defeat the asynchronous behavior and make it blocking? 🤒

eldebtor
Автор

Awesome vid; glad I stumbled upon this! Much cleaner than threading/mp libraries, so I want to learn this one! Why does main have to be async def main and not just def main? Also, does that mean that any functions I use in the async module must have with the async keyword in the definition?

kovi
Автор

For a noob like me this was awesome! Thank you

bogdanvelica
Автор

Nice explanation, very helpfull for me. A huge thanks !!

tonik
Автор

Can I use this to constantly check if a program is running, then make an if statement saying if the program is not running open a file and if it’s already running print the name of the current file it’s running? I’m trying to make this but with a start and stop button…

blizzred
Автор

Your voice & accent sounds a lot like Naval Ravikant
😃

pennystriker
Автор

are u using python 3.10?? bcs some function has depreced

gamingland
Автор

@7:15 isnt the function kill_time() already called before you do await.gather()

abtheminecraft
Автор

6:57 No.
Use list_of_tasks = [kill_time(i) for i in range(1000)]

hughdunc
Автор

Can you please provide source code for these videos

compscif
Автор

11:15 I am strongly against waiting like that. I would loop or create something awaitable instead, but I want to learn it, and you giving me an anti-pattern like that makes me question the usefulness of the rest :/

TojikCZ