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

  Рет қаралды 28,218

PyCon 2018

PyCon 2018

Күн бұрын

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 жыл бұрын
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 жыл бұрын
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?
@donha475
@donha475 4 жыл бұрын
Very good talk
@rujingwang1476
@rujingwang1476 2 жыл бұрын
Are there more lectures by Nathaniel J. Smith ? Best presenter ever
@killerthoughts6150
@killerthoughts6150 10 ай бұрын
A m a z i n g
@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.
@AbeDillon
@AbeDillon 5 жыл бұрын
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 жыл бұрын
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 жыл бұрын
*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 жыл бұрын
:-) > 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 KZbin use, and shouldn't KZbin be sponsoring the work of your community?
@nikjs
@nikjs 5 жыл бұрын
so civilized.
@RoamingAdhocrat
@RoamingAdhocrat 3 жыл бұрын
16:55 nice
@gaatutube
@gaatutube 5 жыл бұрын
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 жыл бұрын
Wow! This is worthless
@nocturn9x
@nocturn9x 6 ай бұрын
lol says who
ДЕНЬ УЧИТЕЛЯ В ШКОЛЕ
01:00
SIDELNIKOVVV
Рет қаралды 2,9 МЛН
Spongebob ate Michael Jackson 😱 #meme #spongebob #gmod
00:14
Mr. LoLo
Рет қаралды 10 МЛН
Win This Dodgeball Game or DIE…
00:36
Alan Chikin Chow
Рет қаралды 39 МЛН
Watermelon magic box! #shorts by Leisi Crazy
00:20
Leisi Crazy
Рет қаралды 58 МЛН
David Beazley - Reinventing the Parser Generator  - PyCon 2018
45:01
Trio: Structured Concurrency for Python
44:59
PyCon South Africa
Рет қаралды 755
Kyle Knapp - Automating Code Quality - PyCon 2018
29:45
PyCon 2018
Рет қаралды 10 М.
Lisa Roach - Demystifying the Patch Function   - PyCon 2018
37:07
PyCon 2018
Рет қаралды 46 М.
Carol Willing - Practical Sphinx - PyCon 2018
27:21
PyCon 2018
Рет қаралды 33 М.
Raymond Hettinger, Keynote on Concurrency, PyBay 2017
1:13:53
SF Python
Рет қаралды 152 М.
Carl Meyer - Type-checked Python in the real world - PyCon 2018
32:10
ДЕНЬ УЧИТЕЛЯ В ШКОЛЕ
01:00
SIDELNIKOVVV
Рет қаралды 2,9 МЛН