AsyncIO and the Event Loop Explained

แชร์
ฝัง
  • เผยแพร่เมื่อ 4 ต.ค. 2024

ความคิดเห็น • 63

  • @ArjanCodes
    @ArjanCodes  5 หลายเดือนก่อน

    💡 Get my FREE 7-step guide to help you consistently design great software: arjancodes.com/designguide.

  • @Testmail-lu8tl
    @Testmail-lu8tl 5 หลายเดือนก่อน +14

    Please make more videos on asyncio and asynchronous programming in python, also how newer versions of python dealing with GIL

  • @__mostafa__
    @__mostafa__ 5 หลายเดือนก่อน +2

    What's better than Arjan uploading a new video?🤩

    • @ArjanCodes
      @ArjanCodes  5 หลายเดือนก่อน

      Ahah! Thank you for the support :)

  • @maxthomarino
    @maxthomarino 2 หลายเดือนก่อน

    you did an excellent job at explaining it in depth, I appreciate the respect fo technical details

  • @paxdriver
    @paxdriver 5 หลายเดือนก่อน

    Thank you so so much for this channel. I'm building an app serving fastapi json data from Python parsers I built from tips from this channel. You introduce newbies to so many advanced tools that seem daunting, it's such a huge help

    • @ArjanCodes
      @ArjanCodes  5 หลายเดือนก่อน

      Glad to hear the videos have had a positive impact on your journey. Cheers!

  • @davidl3383
    @davidl3383 5 หลายเดือนก่อน

    Exactly my week's problem. Not a simple library, but very interesting and powefull.Thank you Arjan

    • @ArjanCodes
      @ArjanCodes  5 หลายเดือนก่อน

      Glad it was helpful!

  • @abdelghafourfid8216
    @abdelghafourfid8216 5 หลายเดือนก่อน +2

    I'd love going more in depth about advanced features and functionalities like Semaphore etc

  • @УважаемыйЧеловек-л4с
    @УважаемыйЧеловек-л4с 5 หลายเดือนก่อน +20

    8:09 threads doesnt have limitations because of GIL if we speak about concurrency and compare it with asyncio. GIL just allows only one thread per process to run at a time. But process can still switch between threads, just like asyncio event loop switch between tasks but within single thread.
    GIL just doesnt allow parallel execution of threads on multiple system threads/cores/CPUs as u like. Its nothing to do with IO, but with CPU time

    •  5 หลายเดือนก่อน

      Yes but as you cannot run threads in parallel and use them for only IO a lighter solution in terms of context switching is better and scales better

    • @sinancetinkaya
      @sinancetinkaya 5 หลายเดือนก่อน +2

      With threads we have more serious problems like thread safety, object sharing, race conditions. AsyncIO is a life saver.

    • @cheatoffchannel6320
      @cheatoffchannel6320 5 หลายเดือนก่อน +2

      ​@@sinancetinkaya lol, race conditions are also possible with asyncio

    • @motbus3
      @motbus3 5 หลายเดือนก่อน

      @@cheatoffchannel6320 you can have race conditions with a single thread and no concurrency at all for x in loop: loop.append(1)

    • @Han-ve8uh
      @Han-ve8uh 4 หลายเดือนก่อน

      Thanks for clarifying, exactly what i thought too. It's confusing to say GIL is a disadvantage of threading with IO bound tasks when asyncio is also doing 1 thing at any moment to the same effect of GIL. I wish cooperative vs preemptive multitasking was mentioned so audience can learn for themselves the differences in whether it's the process(asyncio) or system(multithread) that initiates the context switch

  • @cristeapaul5634
    @cristeapaul5634 5 หลายเดือนก่อน

    Thank you for this video! Really helpful!
    I would also appreciate if you can deep dive in asyncio library and discuss about canceled tasks and proper exception handling.😁

  • @yickysan
    @yickysan 5 หลายเดือนก่อน

    Great video. Exactly what I needed for my current task.

    • @ArjanCodes
      @ArjanCodes  5 หลายเดือนก่อน

      Glad it was helpful!

  • @crysiank
    @crysiank 5 หลายเดือนก่อน +19

    I fully agree that Python's standard library needs more async support.

    • @James-vd3xj
      @James-vd3xj 5 หลายเดือนก่อน +1

      I'm curious why it was never implemented as a standard from the get-go. Do you know if there were technological limitations or other reasons at the time that prevented async from becoming part of Python's standard library earlier? It would be great to understand the historical context to see how we might push for more comprehensive async support in the future.

    • @cheatoffchannel6320
      @cheatoffchannel6320 4 หลายเดือนก่อน

      @@James-vd3xj because threading is simpler solution and doesn't require special syntax. Main benefit of async is that it is more lightweight, that's it.

    • @James-vd3xj
      @James-vd3xj 4 หลายเดือนก่อน

      @@cheatoffchannel6320 Thanks for the brief explanation.

    • @alonnajman6555
      @alonnajman6555 3 หลายเดือนก่อน +1

      I agree as well

    • @youtubeenjoyer1743
      @youtubeenjoyer1743 2 หลายเดือนก่อน

      Because javascript people bullied python people into adding async/await syntax. Even Guido himself couldn't defend it, so he left. Sad!

  • @paxdriver
    @paxdriver 5 หลายเดือนก่อน +1

    Javascript we workers with fast api is an awesome combo. Promises kick ass.

  • @AllanHansen-n1d
    @AllanHansen-n1d 5 หลายเดือนก่อน +1

    Great video Arjan, but one question/request: What is that kind of diagram you show around 2:50 called? I seems great for communicating high-level logic, and you should consider making a video about those. Greetings from Copenhagen, and have a great day!

    • @Han-ve8uh
      @Han-ve8uh 4 หลายเดือนก่อน +1

      en.wikipedia.org/wiki/Sequence_diagram

    • @kellymoses8566
      @kellymoses8566 4 หลายเดือนก่อน +1

      Sequence diagram

  • @augustusbatilojibba1405
    @augustusbatilojibba1405 5 หลายเดือนก่อน +1

    @ArjanCodes Will you make an async video in python using Django Rest Framework? I will be happy if you make one.

  • @loupniko
    @loupniko 4 หลายเดือนก่อน

    Would be great if you'd make a video on new Python 3.13 features. Especially on --disable-gil option and it's impact on performance.

  • @4355784
    @4355784 5 หลายเดือนก่อน +1

    With async libraries on mysql database. I had to go very low (commit and rollback) instead of simple annotation like in spring boot. It could be cool to have the same annotation with python libs.

    • @eyaldahari
      @eyaldahari 5 หลายเดือนก่อน

      Thanks for that video, Arjan. I still do not understand one thing. If I have an IO bound method or library I am using which do not support asyncio is there a way to wrap it to make it async?

    • @cheatoffchannel6320
      @cheatoffchannel6320 4 หลายเดือนก่อน

      @@eyaldahari asgiref standard library module has decorator sync_to_async, but without proper internal implementation it won't give any benefit in concurrency, it just allows to run from async context.
      For external libs the best way is to use threading, many libs are actually thread-safe, or you can lock critical sections by yourself.

  • @slm6873
    @slm6873 5 หลายเดือนก่อน

    I was surprised the other day, that an mmap to mmap copy (float32->int16 of very large files) was much slower than having async read and write tasks, no matter how I chunked things.

  • @k98killer
    @k98killer 2 หลายเดือนก่อน

    I'm going to soon get some ESP32 development devices and play around with micropython. I'll post code and results on the discord server. Micropython might be a worthwhile topic for some videos, and it looks like a lot of fun.

    • @ArjanCodes
      @ArjanCodes  2 หลายเดือนก่อน +1

      Cool! Yes, please post your findings. 😎

  • @_Gabriwl_
    @_Gabriwl_ 2 หลายเดือนก่อน

    Where do i find the course that teach me how to make this own implementation of web server using asyncio??

  • @adityahpatel
    @adityahpatel 23 วันที่ผ่านมา

    Arjan-I've seen some of ur videos. Can u explain something/anything without writing 100 lines of code? i mean lets jz say how about u explain something without writing a single line of code. Can u do that?

  • @MicheleHjorleifsson
    @MicheleHjorleifsson 4 หลายเดือนก่อน

    With the drive towards API consumption all around us i think having concurrency in the stdlib would be a smart move for the Python folks

  • @jam1239665
    @jam1239665 5 หลายเดือนก่อน

    can you show how to do async calls with AWS resources?

  • @walid7189
    @walid7189 5 หลายเดือนก่อน

    if I am streaming a decent amount of data from lets say multiple IoT devices to a rpi.
    I want to serve the data in real time to the server. If I use the concurrent async way, each job will get executed (or literally sent to the server) while blocking each other and at a point won't be displayed in real time? Am I getting this right?

  • @raphaelobadia7664
    @raphaelobadia7664 5 หลายเดือนก่อน +1

    Actually Fastapi use starlette that use anyo.

    • @aflous
      @aflous 5 หลายเดือนก่อน +2

      anyio*

  • @hansdietrich1496
    @hansdietrich1496 5 หลายเดือนก่อน

    gevent for the win. Same technique under the hood, but all async/await stuff just magically happens.

  • @marckiezeender
    @marckiezeender 5 หลายเดือนก่อน

    I wish there were good async desktop app frameworks.

  • @gper9
    @gper9 5 หลายเดือนก่อน

    Tornado is another great async web framework

    • @_DRMR_
      @_DRMR_ 5 หลายเดือนก่อน

      Tornado did async before it was cool!

  • @zakk6182
    @zakk6182 5 หลายเดือนก่อน

    Cool

  • @v.s.naaviinesh
    @v.s.naaviinesh 5 หลายเดือนก่อน

    cool

  • @plussin2760
    @plussin2760 14 วันที่ผ่านมา

    자바 코틀린에 비해서 동시성이 떨어질 수 있는 원인이 GIL에 있었구나

  • @JohnWalz97
    @JohnWalz97 5 หลายเดือนก่อน

    almost first 😛

  • @bingzhao9314
    @bingzhao9314 2 หลายเดือนก่อน

    can u support Chinese cc.i think Chinese software developer quantities are in top 3. thanks

  • @greob
    @greob 5 หลายเดือนก่อน

    I often write synchronous code, and after a while I realize that I need it to be asynchronous. It’s often painful to redo the entire thing with async in mind, and sometimes I just resort to using threads instead to encapsulate my synchronous code. I always wonder if that’s the right thing to do.