Asyncio in Python - Full Tutorial

Поділитися
Вставка
  • Опубліковано 4 лют 2025

КОМЕНТАРІ • 107

  • @TechWithTim
    @TechWithTim  10 місяців тому +9

    If you want to become a developer in 2024 you can watch my free introduction course here: techwithtim.net/dev - yes, there is a paid course as well but we've provided a free 90 minute course you can go through that explains exactly what you need to do to land a developer job.

    • @benjaminbaxter4103
      @benjaminbaxter4103 10 місяців тому

      Tim, is your course good for software development or engineering?

    • @TechWithTim
      @TechWithTim  10 місяців тому

      @@benjaminbaxter4103 of course it is! That's what it is designed for

    • @noticedcloud
      @noticedcloud 10 місяців тому

      Sorry, but how can I do in Python that while an app is running, printing certain things like a server that prints every time someone enters, it can accept a command in the console without the print overlapping with the command?

    • @BlueBearOne
      @BlueBearOne 4 місяці тому

      You are great Tim. Thank you! We appreciate you!

  • @garrettsmith315
    @garrettsmith315 10 місяців тому +37

    Great work on the visual and graphics here, you have stepped your game up from you early Python/UA-cam days. Glad to be a part of the journey.

  • @soumodas782
    @soumodas782 10 місяців тому +11

    Thanks for the upload Tim. This was a concise and well rounded explanation of asynio usage in Python. Exactly what I was looking for

  • @MrTaddelie
    @MrTaddelie 10 місяців тому +13

    Honestly the short animation what the difference between a thread, process and async task is was the most helpfull thing i've seen since i started hobby programming! Thanks, gonna try read some sensors async now^^

  • @esrx7a
    @esrx7a 10 місяців тому +4

    Clear concepts. Thanks Tim

  • @AntonSokolov-i5k
    @AntonSokolov-i5k 7 місяців тому +3

    Hi Tim, thanks for this tutorial! Clear and on point with good examples!

  • @SAsquirtle
    @SAsquirtle 9 місяців тому +8

    this is an outstanding video, it might just be the single best explanation of asyncio on the internet! well done tim

  • @haimroizman6440
    @haimroizman6440 8 місяців тому

    Really I've heard couple of asyncio tutorials but I have to say, this is the best. Thanks a lot

  • @aih1013
    @aih1013 6 місяців тому

    Thanks

  • @ranicket
    @ranicket 3 місяці тому

    This is so so helpful man. Please do more!

  • @surfzion
    @surfzion 8 місяців тому

    Great tutorial ! I've been struggling with this subject for some time, but this videos has made things much more clear to me. Thank you sir.

  • @JorgeEscobarMX
    @JorgeEscobarMX 7 місяців тому

    Thaank you. I seen this syntax before and I tried to make my own async functions bu t failed. This explanation is amazing. Specially locks explanation. Really useful.

  • @oj43085
    @oj43085 10 місяців тому +1

    Nice explanation! I use semaphores for co-current web request to a client that has some throttling. I like how you explained it and the others which i didn't know about.

  • @GRSG_tech
    @GRSG_tech 10 місяців тому +2

    Thank you Tim for the wonderful presentation of Asyncio.
    I'd like for a full python course which for an intermediate level to advanced like diving into machine learning, computer vision(OpenCV or YOLO) and other data science
    Anyways Great content, appreciate it

  • @hackerzone2002
    @hackerzone2002 5 місяців тому +3

    A best content for the async on the whole internet. I was struggling for few hours to understand the actual concept of the async function but i am not able to understand i was stucked at the loop but after watching your content I have understand this topic very well. Thank you

  • @danielcrigan1301
    @danielcrigan1301 10 місяців тому

    Decent course guide! I am working now with aiogram 3.0 framework for buildigt tg chatbots. Watching your video made asyncio easier to understand!

  • @petegranneman1623
    @petegranneman1623 8 місяців тому

    Great tutorial! Great depth while still being very accessible. Keep up the great work! Perhaps worth a mention for our Spyder brethren and sistren... the iPython console runs its own loop which can interfere with the asyncio code. If the iPython console throws errors when running asyncio code, (but the code runs just fine in terminal), the nest_asyncio package can be imported to improve compatibility in the iPython console.

  • @kerrykreiter445
    @kerrykreiter445 10 місяців тому +1

    Excellent work! Thank you!!

  • @nicolaspillot5789
    @nicolaspillot5789 9 місяців тому

    Great tutorial, simple, concise, clear. I like it.

  • @joshuaarinaitwe8351
    @joshuaarinaitwe8351 9 місяців тому

    Thanks tim. Glad to have followed you from way back. Great video

  • @rajeshseemakurthi1595
    @rajeshseemakurthi1595 8 місяців тому

    Awesome Video and helpfulll for middle class learners..Great Contribution bro.

  • @kartiksunaad
    @kartiksunaad 4 місяці тому

    This was really helpful for me. Thanks a lot!

  • @yagneshbhadiyadra7938
    @yagneshbhadiyadra7938 2 місяці тому

    21:12 thank you for this clarification

  • @felipehenriquepeixotoneto9464
    @felipehenriquepeixotoneto9464 2 місяці тому

    You're are the best! Thank you for the video!

  • @benbork9835
    @benbork9835 12 днів тому

    extremely good explanation

  • @hayashii5837
    @hayashii5837 7 місяців тому

    The OG blessing us with his knowledge

  • @nraw_
    @nraw_ 7 місяців тому

    Pretty cool. It would be nice if it also covered some more knowledge on how to mix def and async def functions in bigger projects.

  • @Jesse32142
    @Jesse32142 3 місяці тому

    Super helpful, thank you!

  • @idopshik
    @idopshik 8 місяців тому

    Subscribed fast. Top quality.

  • @ushmita24
    @ushmita24 3 місяці тому

    thanks ! this was so helpful!

  • @MrBodonyi
    @MrBodonyi 3 місяці тому

    TASK section: If print is used instead of return in the fetch_data function.
    corutine: 1
    corutine: 2
    corutine: 3
    corutine is finished: 3 ,time: 2024-10-24 23:15:51.105210
    corutine is finished: 1 ,time: 2024-10-24 23:15:52.103923
    corutine is finished: 2 ,time: 2024-10-24 23:15:53.097646

  • @arunkutube
    @arunkutube 2 місяці тому

    concise and great.

  • @AnoNymous-dh2sv
    @AnoNymous-dh2sv 2 місяці тому

    that's a proper organization of thoughts

  • @MrDerterminator1992
    @MrDerterminator1992 9 місяців тому

    @TechWithTim: Awesome tutorial. I used asyncio already in a couple of projects and never really understood the concept of coroutines. What I also came across is Rate Limiting. So it would be awesome if u could add Semaphores in a future video to have a usecase for async API Requests and Concurrency Limiting with Semaphores.

  • @SergeiTsukanov-o3o
    @SergeiTsukanov-o3o 5 місяців тому +1

    Bro, you are really a master in explaining difficult things in such an easy way

  • @toshailendra
    @toshailendra Місяць тому

    Thanks Tim, It wont get more clear then this.

  • @bassimeledath2224
    @bassimeledath2224 3 місяці тому

    FINALLY it makes sense

  • @Graham_Wideman
    @Graham_Wideman 2 місяці тому

    10:38 "the next important concept which is a task". But hang on, we supposedly just talked about tasks in the previous example... at least there were variables named task1 and task2. But maybe those were incorrectly named, and should have been called coroutine1 and 2? Because apparently (10:38) asyncio.create_task(coroutine) does something different, presumably returning something different than the task1 and task2 of the previous example. More red-herringly, having previously learned that executing a (coroutine? task?) requires awaiting it. Yet evidently in the (10:38) example, asyncio.create_task does not just create a task, it executes it (adds it to the event loop)... and the subsequent three awaits DON'T execute the tasks, but just wait for them to finish.
    Takeaways: "create_task()" should be named "create_and_execute_task()", and the "await" keyword should be named "run_if_not_running_then_await_with_some_yield_opportunities".
    It seems that the asyncio apparatus is not really all that complicated, but dang the asyncio landscape is riddled with unhelpfully-named features and concepts, and so many community explanations and examples that vaguely allude to how things work without managing to hit the target.

  • @yaswanthanumolu765
    @yaswanthanumolu765 7 місяців тому

    clear info 👍

  • @pgrvloik
    @pgrvloik 9 місяців тому +27

    it's difficult to me to comprehend that an async function is actually synchronous, since "awaited'

    • @hughesadam87
      @hughesadam87 7 місяців тому +5

      Agreed. I think of it like async keyword makes a function potentially asynchronous but we can still use the function synchronously if need be😊

  • @SurajKumar-sj5xo
    @SurajKumar-sj5xo Місяць тому

    I really loved the presentation.... on which platform he made this presentation ??

  • @brokenbe
    @brokenbe 4 місяці тому

    Perfect, thank you

  • @chrisw1462
    @chrisw1462 10 місяців тому

    @15:20 I don't disagree with how this was done, but for a demonstration I think I would have made sleep_time a list, and used a range() for 'id' in the for loop. And let 'id' be zero for the first one. A little clearer what's happening with the tasks, imo.

  • @gdefombelle
    @gdefombelle 3 місяці тому

    Excellent !

  • @tarzanat3409
    @tarzanat3409 10 місяців тому +3

    Hey tim, have u ever did something with Microsoft Graph?

  • @satyabharadwaj7779
    @satyabharadwaj7779 10 місяців тому +1

    Hey Tim, just need a clarification on the usage of threads. Do they really work in 'parallel', especially in python? Cause I often here that GIL prevents threads from running threads in parallel, but they are efficient given the fact that a thread waiting for I/O tasks can be suspended and allow other thread to run.

  • @weedfreer
    @weedfreer 10 місяців тому +2

    So, if I needed to call other functions from my async function in order to complete my async function, would the other functions also need to be created as async functions or can they just be regular functions?

    • @TechWithTim
      @TechWithTim  10 місяців тому +1

      they can be normal functions unless you want to run them concurrently

    • @weedfreer
      @weedfreer 10 місяців тому

      @@TechWithTim if many instances of the same concurrent function were attempting to run their own instance of the same standard 'tertiary' function, would that cause a problem, or, would the tertiary function also need to be concurrent?

  • @aleman12345
    @aleman12345 2 місяці тому

    what is recommended when uploading several files to a database? async, thread or process?

  • @adarmawan117
    @adarmawan117 10 місяців тому

    Hi Tim. Please, create video that explaind how to connect Firebase with Python. And how to use general function.
    Thankss

  • @schwaboy
    @schwaboy 4 місяці тому

    TIL about asyncio.Lock(). Thanks!

  • @redwud09
    @redwud09 7 місяців тому

    This is a good one although it would be great without the motion effect at the background, for me just added distraction.

  • @aashayamballi
    @aashayamballi 10 місяців тому +1

    Thanks

  • @ygr4943
    @ygr4943 8 місяців тому +1

    Beautiful explanation. Thank youu ❤❤❤

  • @chrisw1462
    @chrisw1462 10 місяців тому

    @16:02 'Gives .. access to' is a bit misleading, as 'tg' doesn't exist before this line. The whole interface is a bit clunky, IMO, so stuff like that just makes it harder to understand.

  • @adityahpatel
    @adityahpatel 2 дні тому

    there are several loopholes. 7:23 why await sleep and not just sleep? you dont explain

  • @artemiasalina1860
    @artemiasalina1860 10 місяців тому

    How well does asyncio play with Qt's (PySide) event system? Do they interfere with each other? I'm writing a chat client that uses PySide6 for its UI in order to learn python better and am having a hard time deciding how to handle network I/O with asynchronous socket reads and Qt's signal/slot event system. I know that Qt has it's own networking classes like QTCPSocket but I'm specifically trying to avoid using them in order to learn Python's own native async mechanism. Any advise would be appreciated.

  • @theoneandonly2441
    @theoneandonly2441 Місяць тому

    Hello, been trying out asyncio for my python app. However, when i tried to search for any nearby bluetooth devices, it closes the app. Which is strange because it never closes when I tried it after running it from VS Code but it does when I run it as an exe file.

  • @mihhailkapustin7886
    @mihhailkapustin7886 9 місяців тому

    Coming from JS background asyncio has always been super confusing to me. Could you perhaps make a video explaining the difference between JavaScript promises model and Python’s asyncio?

  • @yagneshbhadiyadra7938
    @yagneshbhadiyadra7938 Місяць тому

    What is the color theme you use?

  • @tochimclaren
    @tochimclaren 5 місяців тому

    I'm asking... As a Django developer, do we still need celery?

  • @ti6i
    @ti6i 10 місяців тому

    Quick question:
    Lets assume I make a class with nothing but async functions, if I call the async functions inside another file, lets say I call hello_world() and then I call async_function() and then hello_world() again, would the program freeze while waiting for the hello_world function to execute? Will it execute the hello_world function the 2nd time as the async_function is running?

    • @TechWithTim
      @TechWithTim  10 місяців тому +1

      well it depends on how you call it, you can't call a coroutine without awaiting it or running it some kind of task or future. So in this case if you awaited it ya it would freeze, but if you ran your hello_world() functions and your async_function() concurrently with tasks then it would not wait, it would go and execute the other hello _world function as soon as it encounters any blocking code

  • @dekisugihidetoshi9397
    @dekisugihidetoshi9397 9 місяців тому +1

    Can anyone explain to me the loop
    For i, sleep_time in enumerate([2,1,3], start=1): ?
    Thank you in advance

    • @seelam.hemasasank
      @seelam.hemasasank 8 місяців тому +1

      Enumerate function return the two values (index, value in the list) by default start valve == 0 if you give the start value the index starts from there.
      Every time it creates task and run the async func and sleeps the fun for given secs in list.

  • @pjotrekse
    @pjotrekse 8 місяців тому

    What is the theme called that you use in this tutorial?

  • @ZelabsAdministration
    @ZelabsAdministration 10 місяців тому

    Sorry, but how can I do in Python that while an app is running, printing certain things like a server that prints every time someone enters, it can accept a command in the console without the print overlapping with the command?

  • @GustelEis
    @GustelEis 7 місяців тому

    Like... very much

  • @AlexJaeger716
    @AlexJaeger716 9 місяців тому

    What if i want the code to dynamically create tasks to run concurrently? Is this possible? It seems like the tasks need to be hard coded from everything i’ve seen

  • @SydneyBrown-z5s
    @SydneyBrown-z5s 4 місяці тому

    Thanks for sharing your knowledge with us but could you please stop the pop ups of text on an orange background. It tends to become a nuisance very quickly.

  • @ffzz007
    @ffzz007 10 місяців тому

    I just opened youtube to search for this topic and there you go😂

  • @markobogosavljevic1174
    @markobogosavljevic1174 5 місяців тому

    Why did you say “Full video” in title if you’re going to skip some concepts? I was expexting a more detailed video rather than a quick start guide. Other than that 😡, VERY good video 10/10 delivery!

  • @WaldoTheWombat
    @WaldoTheWombat 10 місяців тому

    Not sure I understand the difference between Asyncio and multithreading. Aren't they both used for IO bound situations?

    • @soumodas782
      @soumodas782 10 місяців тому +1

      Yes but Async IO gives you direct control of the event loop to control concurrency.
      In multi threading , the GIL (global Interpreter Lock) only emulates concurrency with kernel handling much of the scheduling side of the control flows

    • @WaldoTheWombat
      @WaldoTheWombat 10 місяців тому

      @@soumodas782 thanks!

    • @eugenmalatov5470
      @eugenmalatov5470 10 місяців тому

      I don't understand 😓

  • @Monduras
    @Monduras 7 місяців тому

    Does this work with python 3.8?

  • @lhcunha1
    @lhcunha1 6 місяців тому

    this is very hard for me to understand. I'll be watching this video everyday until it sticks into my brain

  • @mahdymokhtari174
    @mahdymokhtari174 6 місяців тому

    OG

  • @ScottKrehbiel
    @ScottKrehbiel 5 місяців тому

    I posted a concern, but Tim has now contacted me and we're discussing the situation.

    • @TechWithTim
      @TechWithTim  5 місяців тому

      What are you talking about? I never received an email nor do I know the program you are discussing. If this is with algoexpert I am no longer affiliated with them and have no control over that program

    • @ScottKrehbiel
      @ScottKrehbiel 5 місяців тому

      @@TechWithTim Yes, this was with the AlgoExpert site. I had emailed you at the address listed on that site.

    • @ScottKrehbiel
      @ScottKrehbiel 5 місяців тому

      @@TechWithTim Have you taken down your videos where you advertise that you teach through that site? It was due to those videos that I signed up there. Yes, the address where I emailed you is the address which AlgoExpert listed as your contact.

    • @TechWithTim
      @TechWithTim  5 місяців тому

      @@ScottKrehbiel unfortunately I have no control of that product so you’ll need to message their team not me

    • @TechWithTim
      @TechWithTim  5 місяців тому

      @@ScottKrehbiel unfortunately I have no control of that product so you’ll need to message their team not me

  • @dennisdegraphicsdynamo_999
    @dennisdegraphicsdynamo_999 10 місяців тому

    Tim I thought your course are free

    • @TechWithTim
      @TechWithTim  10 місяців тому +2

      Most of them are but my premium one is not. It would be impossible for me to help everyone the way I do in that course if it was free

    • @dennisdegraphicsdynamo_999
      @dennisdegraphicsdynamo_999 10 місяців тому

      @@TechWithTim okay I get you

    • @dennisdegraphicsdynamo_999
      @dennisdegraphicsdynamo_999 10 місяців тому

      @@TechWithTim But we need more complex but beginner friendly projects on python and also Ai so that we can also learn.....you are really helping us

  • @vrk3337
    @vrk3337 3 місяці тому

    From somebody who has been developing in Java for 24 years - futures/promises in Python asyncio seem less intuitive than in Java. I understand that any language needs to grow, but going this way in Python invalidates ease of use prerogative.

  • @noticedcloud
    @noticedcloud 10 місяців тому

    Sorry, but how can I do in Python that while an app is running, printing certain things like a server that prints every time someone enters, it can accept a command in the console without the print overlapping with the command?