No video

Learn Python's AsyncIO in 15 minutes

  Рет қаралды 51,364

Indently

Indently

Күн бұрын

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:
www.indently.io
▶ Follow me on Instagram:
/ indentlyreels
Documentation:
docs.python.or...

Пікірлер: 42
@WDieSmile
@WDieSmile Жыл бұрын
Simple but most essential and elegant explanations for the asyncio. Huge thanks!
@eitantal726
@eitantal726 3 ай бұрын
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
@djbroake9810
@djbroake9810 Жыл бұрын
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 = [loop.create_task(kill_time(i)) 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 = asyncio.create_task(kill_time(i)) list_of.append(task) await asyncio.gather(*list_of)
@YoKKJoni
@YoKKJoni 3 ай бұрын
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..
@valorantaccount462
@valorantaccount462 Жыл бұрын
thanks really understood the concept.
@artem_isakow
@artem_isakow 9 ай бұрын
Very clear 👌
@emailvinz
@emailvinz 7 ай бұрын
Very clear, thank you very much !
@grzegorzryznar5101
@grzegorzryznar5101 Жыл бұрын
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 :)
@vnikolayev
@vnikolayev Жыл бұрын
Great video, thanks!
@ramima6465
@ramima6465 5 ай бұрын
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.
@cusematt23
@cusematt23 7 ай бұрын
I think this video is great. Very clear.
@umbertoarreghini9307
@umbertoarreghini9307 Жыл бұрын
👏Clear and concise
@supundasanthakuruppu3496
@supundasanthakuruppu3496 8 ай бұрын
This was very helpful. Thank you.
@alexiswiftrock
@alexiswiftrock Жыл бұрын
Thanks for this exposition 👍
@skyisthelimpet
@skyisthelimpet Жыл бұрын
Thanks for the explanation
@Arocksy
@Arocksy Жыл бұрын
Thanks for a simple explanation!
@bogdanvelica
@bogdanvelica Жыл бұрын
For a noob like me this was awesome! Thank you
@kovi5758
@kovi5758 Жыл бұрын
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?
@eldebtor6973
@eldebtor6973 5 ай бұрын
doesnt await defeat the asynchronous behavior and make it blocking? 🤒
@eugenmalatov5470
@eugenmalatov5470 4 ай бұрын
i think the explanation is wrong. Await starts a async coroutine, nothing to do with waiting afaik.
@joakker8820
@joakker8820 Ай бұрын
If I understand correctly, if you await, the execution will continue in another coroutine, which could be the one you just created, or another
@hillolbro
@hillolbro Жыл бұрын
This is arguably the best asyncio-await explanation on youtube!. thanks for keeping it simple to understand!
@findritesh
@findritesh Жыл бұрын
great tutorial!
@blizzred2143
@blizzred2143 7 ай бұрын
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…
@gamingland2074
@gamingland2074 2 жыл бұрын
are u using python 3.10?? bcs some function has depreced
@tonik04
@tonik04 Жыл бұрын
Nice explanation, very helpfull for me. A huge thanks !!
@sc0820
@sc0820 Жыл бұрын
very nice
@abtheminecraft
@abtheminecraft Жыл бұрын
@7:15 isnt the function kill_time() already called before you do await.gather()
@e_a_r_t_h_m_a_n
@e_a_r_t_h_m_a_n 7 ай бұрын
coroutines (any function with `yield` or `await` inside) should be `extracted` from a function first by a call syntax. But this call is not a call, it just returns a `coroutine` object.
@pennystriker
@pennystriker Жыл бұрын
Your voice & accent sounds a lot like Naval Ravikant 😃
@hughdunc
@hughdunc Жыл бұрын
6:57 No. Use list_of_tasks = [kill_time(i) for i in range(1000)]
@Slay_and_Play
@Slay_and_Play Жыл бұрын
Why do you need list comprehension versus what he had?
@compscif5032
@compscif5032 2 жыл бұрын
Can you please provide source code for these videos
@Indently
@Indently 2 жыл бұрын
I don’t have source code for these videos
@__lasevix_
@__lasevix_ 2 жыл бұрын
@@Indently you delete all the example files after writing ?
@Indently
@Indently 2 жыл бұрын
@@__lasevix_ Yeah, I don't share source code in general for non-project videos
@alexiswiftrock
@alexiswiftrock Жыл бұрын
Just follow along in practice. Not everything has to be a handout.
@TojikCZ
@TojikCZ Жыл бұрын
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 :/
@Indently
@Indently Жыл бұрын
You can be strongly against whatever you want. The sleep can also be set to 0 if you want, but you need to provide your script some context to be able to perform a switch or it never will.
@trzztrzz2477
@trzztrzz2477 9 ай бұрын
fuoco frigiteli y adizo
@Alex-bw8wr
@Alex-bw8wr Жыл бұрын
Not super useful 😢
@Indently
@Indently Жыл бұрын
Thank you for the useful comment 😉
5 Good Python Habits
17:35
Indently
Рет қаралды 503 М.
Survive 100 Days In Nuclear Bunker, Win $500,000
32:21
MrBeast
Рет қаралды 165 МЛН
Python Asyncio, Requests, Aiohttp | Make faster API Calls
17:56
Patrick Collins
Рет қаралды 130 М.
How To Easily Do Asynchronous Programming With Asyncio In Python
23:09
Intro to async Python | Writing a Web Crawler
14:23
mCoding
Рет қаралды 77 М.
How To Read Word Documents In Python
4:50
Taylor's Software
Рет қаралды 2,3 М.
AsyncIO & Asynchronous Programming in Python
12:28
NeuralNine
Рет қаралды 153 М.
AsyncIO, await, and async - Concurrency in Python
9:12
Socratica
Рет қаралды 91 М.
5 Useful Python Decorators (ft. Carberra)
14:34
Indently
Рет қаралды 97 М.
Python Asynchronous Programming - AsyncIO & Async/Await
25:57
Tech With Tim
Рет қаралды 423 М.
Python dataclasses will save you HOURS, also featuring attrs
8:50
10 Important Python Concepts In 20 Minutes
18:49
Indently
Рет қаралды 57 М.