Miguel Grinberg Asynchronous Python for the Complete Beginner PyCon 2017

  Рет қаралды 121,554

PyCon 2017

PyCon 2017

Күн бұрын

"Speaker: Miguel Grinberg
With the introduction of the asyncio package in Python 3.4, you can hear lots of people talking about asynchronous programming, most in a favorable way, some not so much. In this talk, I will tell you what this async fever is about and what can it do for you that regular Python can't, not only with asyncio, but also with other frameworks that existed long before it.
Slides can be found at: speakerdeck.com/pycon2017 and github.com/PyCon/2017-slides"

Пікірлер: 69
@IsItTimeToTravel
@IsItTimeToTravel 5 жыл бұрын
This is how one should teach . That chess example is the best anyone could have given .
@knight024
@knight024 4 жыл бұрын
Couldn't agree more - it's the perfect analogy to use.
@-__--__aaaa
@-__--__aaaa 3 жыл бұрын
@Lou Kaluzny lol😆😆
@ehza
@ehza Жыл бұрын
word!
@experimentalhypothesis1137
@experimentalhypothesis1137 3 жыл бұрын
miguel is a legend. i really like how humbly he speaks
@fredrikaverpil
@fredrikaverpil 7 жыл бұрын
Very nice talk, cleared up a bunch of questions I had on asyncio.
@kellymoses8566
@kellymoses8566 3 жыл бұрын
You don't really understand something until you can think of a really good analogy to explain it.
@jaroslawmichalski9021
@jaroslawmichalski9021 7 жыл бұрын
so simple, but surprisingly good and very informative
@RajeshRRajamani
@RajeshRRajamani 3 жыл бұрын
I felt the chess analogy cleared my confusions here . Thank you so much .
@piyushkatariya1040
@piyushkatariya1040 6 жыл бұрын
Always a good and clear talk. Thanks Miguel
@andrealmar04
@andrealmar04 7 жыл бұрын
very good talk. clear concepts and examples
@shashishekhar----
@shashishekhar---- Жыл бұрын
You are awesome Miguel, seldom have I seen such complex things explained and put into perspective this easily, take care and god bless you and your family.
@mathematixal
@mathematixal 5 жыл бұрын
Wonderful overview of not only async but the advantages over multiprocess/multithread. It is good point that asyncio is designed to make you write/think in an async way.
@rickylim4910
@rickylim4910 6 жыл бұрын
great talk, very straightforward as it is.
@novie952
@novie952 6 жыл бұрын
Very clear explanation !
@MaulinTolia
@MaulinTolia 5 жыл бұрын
Please give this man more time!
@Ubben1999
@Ubben1999 7 жыл бұрын
Reading Miguel's Flask book right now. He's a great writer, and apparently a pretty good speaker as well.
@girirajrdx7277
@girirajrdx7277 2 жыл бұрын
Suggests some of his books pls
@lator1941
@lator1941 Жыл бұрын
I read 5 articles and it wasn't until I watched this that I had deep understanding of the concept
@Johnged15
@Johnged15 6 жыл бұрын
Appreciate this channel sharing this very informative content.
@temaz3334
@temaz3334 7 жыл бұрын
Love Miguel teaching many years!
@nikitasid4947
@nikitasid4947 7 жыл бұрын
Great! Thanks, Miguel.
@usf5914
@usf5914 4 жыл бұрын
1:51 simple definition of async programming 2:23 ways to do multiple things at once(concorrent programming) 3:57 async programming(example : play with a chess champion) 8:12 complete definition 8:42 how is async implemented( functions need the ability to suspend and resume 10:04 which function gets the CPU next(the idea of cooperative multitasking (event loop) ) ) 11:00 examples[this slide have like to more exampels]( 11:54 Asyncio example[use generator function VS async/await] 14:39 greenlet framework example[gevent VS eventlet] ) 16:03 Async pitfalls( 16:21 asyncio.sleep(0) 17:42 blocking!? ) 20:28 conclusion
@juvewan
@juvewan 4 жыл бұрын
I fininally understand what Aysnc means. That chart comparing Process vs Thread vs Async is gold!
@arjunkirpal9776
@arjunkirpal9776 6 жыл бұрын
Miguel Grinberg thanks.
@driziiD
@driziiD 4 жыл бұрын
100% the chess example is hands-down the BEST possible example
@venkateshsrinivasan150
@venkateshsrinivasan150 4 жыл бұрын
Brilliant talk!
@shamen2
@shamen2 5 жыл бұрын
Excellent talk !!!
@r3ap3rpy
@r3ap3rpy 6 жыл бұрын
Great talk!
@shreerangaraju1013
@shreerangaraju1013 3 жыл бұрын
Brilliant analogy!
@fuanka1724
@fuanka1724 6 жыл бұрын
Thanks Miguel.
@cosmicallyderived
@cosmicallyderived 6 жыл бұрын
This came up in the next recommended videos, and I wasn't particularly immediately interested in the topic as far as today was concerned (though I did have a todo interest for future review). But once I saw Miguel Grinberg was the speaker, I ponied up for the watch.
@shashishekhar----
@shashishekhar---- Жыл бұрын
same
@ashu9sharma
@ashu9sharma 5 жыл бұрын
couldn't have explain it better :)
@duongkstn
@duongkstn Жыл бұрын
thanks for sharing
@XieQiu
@XieQiu 5 жыл бұрын
as a chess player i really appreciate the example.
@vcool
@vcool 6 жыл бұрын
The indicated examples are at j.mp/asyncpython
@BharathiFromSouth
@BharathiFromSouth 4 жыл бұрын
How the async program handle the token expiry for oauth. Eg: I have 30 requests running async but first request got the http error meanwhile before handling refresh token we I'll get the all responses.
@ekbastu
@ekbastu 6 жыл бұрын
You rock :)
@youvanced6593
@youvanced6593 Жыл бұрын
Why can't I do web stuff with the multiprocessing library and what is the alternative? Let's say I computer that needs to run a python project that is both a Flask server and also does multiprocessing actions
@MarkusBurrer
@MarkusBurrer 3 жыл бұрын
Async doesn't make your code fast. It makes it just less idle
@rohitbhanot7809
@rohitbhanot7809 5 жыл бұрын
Threads arn't really any use if there are CPU bound tasks and hence GIL is an issue, but with async if GIL is not issue you can do concurrent CPU bound tasks, i think its an important he missed mentioning.
@shashishekhar----
@shashishekhar---- Жыл бұрын
GIL is still there and notice he said that there is actually one thread andprocess involved so there is not much scope for high cpu bound tasks in async.
@SHUBHAMBHARDWAJBCE
@SHUBHAMBHARDWAJBCE 6 жыл бұрын
Can you please share the slides
@saurabh75prakash
@saurabh75prakash 6 жыл бұрын
I have a question on the slide shown at 20:42. For async case how do we prevent the OS scheduler from interfering with async event loop. As per my understanding the async event loop is scheduled by OS?
@Contacke14
@Contacke14 5 жыл бұрын
the OS does not interfere with the event loop. The OS schedules processes and threads, while the event loop is run single-threadedly within one process.
@mrwibbles20
@mrwibbles20 7 жыл бұрын
A good talk. However, the gevent and eventlet examples were mismatched to the preceding "yield from" and "await" examples. Those used a loop to run the functions, which is the natural way to do it as it allows other functions to be also run asyncronously by that loop - hence the 10 call example with 10 hellos, followed by 10 worlds. The gevent and eventlet examples just called each single function in a non asynchronous way.. To be matching, they should have used the corresponding loop from those frameworks to similarly allow 10 versions of those functions to potentially be launched at the same time. The reason I mention this was the point that gevent and greenlet were harder to keep track of, as this omission served no purpose, other than to contrive this point a little.
@miguelgrinberg
@miguelgrinberg 7 жыл бұрын
No, you are actually incorrect. The gevent/eventlet examples are 100% asynchronous. They have a loop and all the function calls are truly async. As I mention in the presentation, these frameworks hide the asynchronous bits from the application, the loop is created implicitly by the framework, so that the application does not need to write the code in a different way. If you call the gevent or eventlet function 10 times in a loop, you'll get 10 hellos, 3 seconds and then 10 worlds, like with asyncio.
@mrwibbles20
@mrwibbles20 7 жыл бұрын
You are right, I judged the code based on the part of the video where you talked about the asyncio function being called 10x and printing 10x. The given gevent/greenlet code was not set up for a beginner easily doing this, where the asyncio version was. I think the gevent and greenlet examples are not representative of actual use, and that in practice most if not all production code based on that tech would use an explicit loop. Given this, the nebulous and otherwise correct warning about hidden complexity, is now extended to implying a loop is not even needed.
@miguelgrinberg
@miguelgrinberg 7 жыл бұрын
The gevent and eventlet examples are 100% correct, and totally representative of how production projects use these frameworks. The event loop in those frameworks exists, but it is implicitly handled by the framework.
@mrwibbles20
@mrwibbles20 7 жыл бұрын
Please link to some of these projects which do not use an event loop.
@miguelgrinberg
@miguelgrinberg 7 жыл бұрын
Any projects that use gevent or eventlet would not explicitly define an event loop. Take any Flask application, run it on a gevent or eventlet based WSGI server and it'll be automatically async, w/o having to make any changes. The examples from my talk are here: gist.github.com/miguelgrinberg/f15bc03471f610cfebeba62438435508#file-eventlet-greenlets-py. Give them a try if you want.
@malayagr
@malayagr 2 жыл бұрын
Didn't know Ben Kingsley wrote Python.
@govardhangd9387
@govardhangd9387 5 жыл бұрын
If asynchronous programming is just a style of concurrent programming, what are the other things that come under the umbrella of concurrent programming??? I thought this is the only way to do concurrent programming...
@magno5157
@magno5157 5 жыл бұрын
You've got to be careful though. Although async is called "concurrent", all the asynchronous tasks that run on the same thread do not actually run at the same time in parallel *at all*! Each async task gets to run for a little bit before it is paused and another task is then started or resumed. The async tasks (on the same thread) just simply take turn to run. Since CPU's are really fast, we get the illusion that async tasks run in parallel when in fact they do not. So, "concurrent" is somewhat a misleading term to describe asynchronous.
@shashishekhar----
@shashishekhar---- Жыл бұрын
@@magno5157 That is actally the meaning of concurrent that you take up multiple tasks at one not neccesarily mutitasking them at the same time while what you are thinking about is called parallelism.
@nxxxxzn
@nxxxxzn 6 жыл бұрын
29:26 holy crap
@xiaolu7988
@xiaolu7988 5 жыл бұрын
4:54 LOL
@vcool
@vcool 6 жыл бұрын
In summary, asyncio is great when at minimum you need thousands of concurrent executions in a process. Threads work for when you need mere hundreds at maximum, albeit with possible race conditions. Also, threaded programming is different and reasoning about it is different.
@lawrencedoliveiro9104
@lawrencedoliveiro9104 6 жыл бұрын
No. Threads are something you only need for CPU performance (which is not what unaided Python is good at). The problem with threads is that they are notoriously prone to bugs. Coroutines are much easier to understand, so if your bottleneck is in the I/O (including network connections), then coroutines are preferable to threads, while offering performance just as good--the potential for race conditions essentially disappears.
@vcool
@vcool 6 жыл бұрын
Lawrence D’Oliveiro In the past, people used threads in Python for blocking I/O. I have corrected the original post.
@lawrencedoliveiro9104
@lawrencedoliveiro9104 6 жыл бұрын
Python’s asyncio deals with that just fine. That’s why it’s a good idea to avoid threads if you don’t need high CPU utilization.
@wschmidt22
@wschmidt22 7 жыл бұрын
Thought it was going to be about Flask.
@hairypaulsack
@hairypaulsack 3 жыл бұрын
1.25x
@SmartManoj
@SmartManoj 2 жыл бұрын
kzbin.info/www/bejne/n3iZl6VuZt17gaM 1hour + 55 second (Last game's Opponent's last move)
Универ. 13 лет спустя - ВСЕ СЕРИИ ПОДРЯД
9:07:11
Комедии 2023
Рет қаралды 6 МЛН
THE POLICE TAKES ME! feat @PANDAGIRLOFFICIAL #shorts
00:31
PANDA BOI
Рет қаралды 17 МЛН
AsyncIO and the Event Loop Explained
13:34
ArjanCodes
Рет қаралды 23 М.
How to Do 90% of What Plugins Do (With Just Vim)
1:14:03
thoughtbot
Рет қаралды 871 М.
Keynote: The big leap of Python 3.13 - Łukasz Langa
30:56
PyCon Thailand
Рет қаралды 10 М.
Brandon Rhodes   The Dictionary Even Mightier   PyCon 2017
47:22
PyCon 2017
Рет қаралды 31 М.
Eric Evenchick   Hacking Cars with Python   PyCon 2017
29:48
PyCon 2017
Рет қаралды 15 М.
Stop Writing Classes
27:29
Next Day Video
Рет қаралды 930 М.
Amjith Ramanujam   Awesome Command Line Tools   PyCon 2017
28:42
PyCon 2017
Рет қаралды 29 М.