Miguel Grinberg Asynchronous Python for the Complete Beginner PyCon 2017

  Рет қаралды 123,429

PyCon 2017

PyCon 2017

Күн бұрын

Пікірлер: 69
@lator1941
@lator1941 Жыл бұрын
I read 5 articles and it wasn't until I watched this that I had deep understanding of the concept
@IsItTimeToTravel
@IsItTimeToTravel 6 жыл бұрын
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 2 жыл бұрын
word!
@kellymoses8566
@kellymoses8566 3 жыл бұрын
You don't really understand something until you can think of a really good analogy to explain it.
@experimentalhypothesis1137
@experimentalhypothesis1137 4 жыл бұрын
miguel is a legend. i really like how humbly he speaks
@RajeshRRajamani
@RajeshRRajamani 4 жыл бұрын
I felt the chess analogy cleared my confusions here . Thank you so much .
@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
@shashishekhar----
@shashishekhar---- 2 жыл бұрын
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.
@fredrikaverpil
@fredrikaverpil 7 жыл бұрын
Very nice talk, cleared up a bunch of questions I had on asyncio.
@driziiD
@driziiD 4 жыл бұрын
100% the chess example is hands-down the BEST possible example
@jaroslawmichalski9021
@jaroslawmichalski9021 7 жыл бұрын
so simple, but surprisingly good and very informative
@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
@piyushkatariya1040
@piyushkatariya1040 7 жыл бұрын
Always a good and clear talk. Thanks Miguel
@juvewan
@juvewan 4 жыл бұрын
I fininally understand what Aysnc means. That chart comparing Process vs Thread vs Async is gold!
@andrealmar04
@andrealmar04 7 жыл бұрын
very good talk. clear concepts and examples
@cosmicallyderived
@cosmicallyderived 7 жыл бұрын
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---- 2 жыл бұрын
same
@MaulinTolia
@MaulinTolia 6 жыл бұрын
Please give this man more time!
@XieQiu
@XieQiu 5 жыл бұрын
as a chess player i really appreciate the example.
@novie952
@novie952 7 жыл бұрын
Very clear explanation !
@rickylim4910
@rickylim4910 6 жыл бұрын
great talk, very straightforward as it is.
@nikitasid4947
@nikitasid4947 7 жыл бұрын
Great! Thanks, Miguel.
@arjunkirpal9776
@arjunkirpal9776 7 жыл бұрын
Miguel Grinberg thanks.
@vcool
@vcool 7 жыл бұрын
The indicated examples are at j.mp/asyncpython
@shreerangaraju1013
@shreerangaraju1013 3 жыл бұрын
Brilliant analogy!
@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.
@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
@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 6 жыл бұрын
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.
@ashu9sharma
@ashu9sharma 5 жыл бұрын
couldn't have explain it better :)
@r3ap3rpy
@r3ap3rpy 6 жыл бұрын
Great talk!
@Johnged15
@Johnged15 6 жыл бұрын
Appreciate this channel sharing this very informative content.
@duongkstn
@duongkstn 2 жыл бұрын
thanks for sharing
@MarkusBurrer
@MarkusBurrer 3 жыл бұрын
Async doesn't make your code fast. It makes it just less idle
@rohitbhanot7809
@rohitbhanot7809 6 жыл бұрын
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---- 2 жыл бұрын
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.
@nxxxxzn
@nxxxxzn 7 жыл бұрын
29:26 holy crap
@fuanka1724
@fuanka1724 6 жыл бұрын
Thanks Miguel.
@SHUBHAMBHARDWAJBCE
@SHUBHAMBHARDWAJBCE 7 жыл бұрын
Can you please share the slides
@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.
@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---- 2 жыл бұрын
@@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.
@ekbastu
@ekbastu 6 жыл бұрын
You rock :)
@malayagr
@malayagr 3 жыл бұрын
Didn't know Ben Kingsley wrote Python.
@vcool
@vcool 7 жыл бұрын
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 7 жыл бұрын
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 7 жыл бұрын
Lawrence D’Oliveiro In the past, people used threads in Python for blocking I/O. I have corrected the original post.
@lawrencedoliveiro9104
@lawrencedoliveiro9104 7 жыл бұрын
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.
@xiaolu7988
@xiaolu7988 5 жыл бұрын
4:54 LOL
@SmartManoj
@SmartManoj 2 жыл бұрын
kzbin.info/www/bejne/n3iZl6VuZt17gaM 1hour + 55 second (Last game's Opponent's last move)
@venkateshsrinivasan150
@venkateshsrinivasan150 5 жыл бұрын
Brilliant talk!
@shamen2
@shamen2 5 жыл бұрын
Excellent talk !!!
Don’t Choose The Wrong Box 😱
00:41
Topper Guild
Рет қаралды 62 МЛН
How Strong Is Tape?
00:24
Stokes Twins
Рет қаралды 96 МЛН
Python is NOT Single Threaded (and how to bypass the GIL)
10:23
Jack of Some
Рет қаралды 111 М.
Yury Selivanov - async/await in Python 3.5 and why it is awesome
25:08
EuroPython Conference
Рет қаралды 26 М.
Python Asyncio, Requests, Aiohttp | Make faster API Calls
17:56
Patrick Collins
Рет қаралды 137 М.
Eric Evenchick   Hacking Cars with Python   PyCon 2017
29:48
PyCon 2017
Рет қаралды 15 М.
Python tricks: Demystifying async, await, and asyncio
15:59
Sebastiaan Mathôt
Рет қаралды 94 М.
Carl Meyer - Type-checked Python in the real world - PyCon 2018
32:10
Don’t Choose The Wrong Box 😱
00:41
Topper Guild
Рет қаралды 62 МЛН