Nathaniel J. Smith - Trio: Async concurrency for mere mortals - PyCon 2018

Поделиться
HTML-код
  • Опубликовано: 28 авг 2024
  • Speaker: Nathaniel J. Smith
    Concurrent programs are super useful: think of web apps juggling lots of simultaneous downloads and websocket connections, chat bots tracking multiple concurrent conversations, or web spiders fetching pages in parallel. But writing concurrent programs is complicated, intimidating to newcomers, and often challenging even for experts.
    Does it have to be? Python is famous for being simple and straightforward; can Python make concurrent programming simple and straightforward too? I think so. By carefully analyzing usability pitfalls in other libraries, and taking advantage of new Python 3 features, I've come up with a new set of primitives that make it dramatically easier to write correct concurrent programs, and implemented them in a new library called [Trio](trio.readthedo...). In this talk, I'll describe these primitives, and demonstrate how to use them to implement a basic algorithm for speeding up TCP connections. Compared to the best previous Python implementation, our version turns out to be easier to understand, more correct, and dramatically shorter.
    This talk assumes basic familiarity with Python, but does not require any prior experience with concurrency, async/await, or networking.
    Slides can be found at: speakerdeck.co... and github.com/PyC...

Комментарии • 19

  • @KevinZJR
    @KevinZJR 5 лет назад +9

    Trio is a big step forward in asynchronous programming IMHO. It's hard to capture its many concepts in such a short talk. If anyone wants to know more, Mr Smith's great blog posts on structured concurrency and cancel scope the place to start.

  • @aweffrle7264
    @aweffrle7264 6 лет назад +6

    Very very helpful talk, thank you. Now I get the feeling that I can implement "Happy Eye Balls" and some other things I did in Rxjs. I'm going to try Trio right now.

    • @armynyus9123
      @armynyus9123 2 года назад

      Just stumbling over trio - question to you: did you try trio? I still like the declarative approach of Rx and was thinking of using Rx in Python as well. Would you say trio is "better", for many use cases?

  • @rujingwang1476
    @rujingwang1476 2 года назад +1

    Are there more lectures by Nathaniel J. Smith ? Best presenter ever

  • @michaelnajera7958
    @michaelnajera7958 4 года назад

    coming from kotlin, I'm glad that structured concurrency is available in Python, also. Great intro

  • @fredeisele1895
    @fredeisele1895 5 лет назад

    Consider the case where an exception is stating that the process has an unbound resource. One of its ancestors should have the opportunity to bind something to that resource so the descendant has a chance to finish its work before it is killed. That is the closing of the child processes is contingent upon the exception being unresolved.

  • @donha475
    @donha475 4 года назад +1

    Very good talk

  • @killerthoughts6150
    @killerthoughts6150 9 месяцев назад

    A m a z i n g

  • @AbeDillon
    @AbeDillon 5 лет назад +1

    I wish Mr. Smith had spent more time explaining what's going on in the diagram at 19:28
    He then jumps to some code where nothing is labeled "nursery" at 19:32
    I know he was given a very short window to speak, but the idea of a nursery seems pretty important and I still don't quite get it.

    • @nathanielsmith2547
      @nathanielsmith2547 5 лет назад +11

      Ah yeah, that bit at 19:32 is kinda unclear, isn't it? It was pretty tough describing the whole "theory of nurseries" in 5 minutes :-). If you want a more leisurely version, I'd recommend this blog post: vorpus.org/blog/notes-on-structured-concurrency-or-go-statement-considered-harmful/
      But about the slide at 19:32 in particular: The point I was trying to make is that in a lot of systems (e.g., twisted, asyncio), a function like proxy_two_way() might just start the proxying happening in the background, so when the function returns, you don't really know whether it's still running. So, just looking at the code on that slide, we can't tell whether it's safe to close the stream handles we passed in -- it might still be using them!
      But in Trio, we know it's safe to close the handles, *even if we have no idea what proxy_two_way actually does.* It might open a nursery internally, but then it has to close that nursery again before it returns, which means that any tasks it spawns have to be finished before it returns. (And in fact if you look at the complete code, at 9:05, then you'll see that it does open a nursery internally!) Because Trio mandates the use of nurseries, the only way proxy_two_way could leave things running after it returns is if we *pass in* a nursery object, and just from the code on the slide at 19:32 we can see that we're not.
      Hope that helps! (And sorry for the slow response, I don't get any notification of comments here. If you have more questions, then gitter.im/python-trio/general is a better place to reach me and the other Trio devs :-).)

    • @AbeDillon
      @AbeDillon 5 лет назад +3

      *Hope that helps! (And sorry for the slow response*
      LOL! You better be sorry for writing such a helpful, informative response! Now get back to making more open source software that I'll probably use to make my life easier!
      Man... complaining about stuff on the internet is such a thankless job ;)
      Honestly, though. This is a fantastic response and I look forward to seeing how Trio develops! I might even pitch in!

    • @nathanielsmith2547
      @nathanielsmith2547 5 лет назад +1

      :-)
      > I might even pitch in!
      That would be awesome. It turns out reinventing I/O and concurrency is kind of a big job, so there's no shortage of places to help :-). If you're interested, we have a handy contributing guide: trio.readthedocs.io/en/latest/contributing.html

    • @simonmasters3295
      @simonmasters3295 5 лет назад

      coding for concurrency is my challenge-problem too, @@nathanielsmith2547 because I have an interest in maker projects (e.g. Arduino-Pi) that require its control at the sub-second (mHz, GHz) level of frequencies
      Makes me think what do RUclips use, and shouldn't RUclips be sponsoring the work of your community?

  • @nikjs
    @nikjs 5 лет назад +2

    so civilized.

  • @RoamingAdhocrat
    @RoamingAdhocrat 3 года назад

    16:55 nice

  • @gaatutube
    @gaatutube 5 лет назад +2

    Somehow the syntax just seems unnatural to me when you say sink.send_eof( ) or sink.send_all(data). Makes it sound like as if sink is the one doing some work, when in fact we want to say "send all data TO sink" or "send an eof to sink". Perhaps a syntax like *trio.send_eof(sink)* or *trio.send_all(data, sink)* would be more intuitive.

    • @kriss1_
      @kriss1_ 5 лет назад

      I think the usage of the word 'sink' as the object name here is very deliberate, to make it implicitly tell you that it isn't actually doing anything itself - just passing through something - like a real sink just passing water through to whatever is at the end of the piping on the other side. Thinking like this makes the usage pretty clear for me.

  • @ggsap
    @ggsap 2 года назад +1

    Wow! This is worthless

    • @nocturn9x
      @nocturn9x 5 месяцев назад

      lol says who