Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #103415

Re: How the heck does async/await work in Python 3.5

Path csiph.com!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From "Sven R. Kunze" <srkunze@mail.de>
Newsgroups comp.lang.python
Subject Re: How the heck does async/await work in Python 3.5
Date Tue, 23 Feb 2016 20:42:49 +0100
Lines 47
Message-ID <mailman.79.1456256573.20994.python-list@python.org> (permalink)
References <mailman.224.1455746935.22075.python-list@python.org> <56c7d145$0$1597$c3e8da3$5496439d@news.astraweb.com> <na92c0$n65$1@dont-email.me> <56CB88D5.3090202@mail.de> <CALwzid=ira=LHuoRPDg_NuchvjfFJ9GKvG_R-tvg29NaN2CXqQ@mail.gmail.com> <56CC8DBD.9080604@mail.de> <CALwzidnBqeBaa=2PhyyMjehabrnLo9R1Jk5LnGfd=mEWTrd=yQ@mail.gmail.com>
Mime-Version 1.0
Content-Type text/plain; charset=windows-1252; format=flowed
Content-Transfer-Encoding 7bit
X-Trace news.uni-berlin.de zUfNp5O/OxGG7eDq2ZgTKQ9aRoFGMDkKs5iapbf8zPIw==
Return-Path <srkunze@mail.de>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.008
X-Spam-Evidence '*H*': 0.98; '*S*': 0.00; 'api.': 0.04; 'subject:Python': 0.05; 'compiler': 0.05; 'none:': 0.05; 'desired.': 0.07; 'executed': 0.07; 'shortcut': 0.07; 'subject:How': 0.09; 'loop.': 0.09; 'python': 0.10; 'def': 0.13; 'file,': 0.15; 'async': 0.16; 'initializes': 0.16; 'ops': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'should.': 0.16; 'usual.': 0.16; 'wrote:': 0.16; 'foundation': 0.19; 'windows': 0.20; '(the': 0.22; 'converted': 0.22; 'explicit': 0.22; 'implicit': 0.22; 'scale.': 0.22; 'seems': 0.23; '(like': 0.23; 'header:In-Reply-To:1': 0.24; 'loop,': 0.29; 'once,': 0.29; 'subject:/': 0.30; 'code': 0.30; 'certainly': 0.30; 'e.g.': 0.30; 'operations': 0.31; 'core': 0.32; 'etc.)': 0.32; 'point': 0.33; 'call,': 0.33; 'wrap': 0.33; 'received:10.0': 0.34; 'so,': 0.35; 'best,': 0.35; 'could': 0.35; 'done': 0.35; 'clear': 0.35; 'c++': 0.35; 'functions.': 0.35; 'replace': 0.35; 'quite': 0.35; 'something': 0.35; 'level': 0.35; "isn't": 0.35; 'but': 0.36; 'there': 0.36; 'subject:work': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'received:10': 0.37; 'agree': 0.37; 'doing': 0.38; 'drop': 0.38; 'anything': 0.38; 'building': 0.38; 'skip:p 20': 0.38; 'end': 0.39; 'subject:the': 0.39; 'easily': 0.39; 'well.': 0.40; 'to:addr:python.org': 0.40; 'still': 0.40; 'received:de': 0.40; 'some': 0.40; 'your': 0.60; 'real': 0.62; 'here.': 0.62; 'charset:windows-1252': 0.62; 'is.': 0.63; 'different': 0.63; 'great': 0.63; 'world': 0.64; 'future,': 0.70; 'introduce': 0.79; 'hand': 0.82; 'awaits': 0.84; 'imagine,': 0.84; "there'll": 0.84; 'wires': 0.84; 'wiring': 0.84; 'technically': 0.91
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/simple; d=mail.de; s=mail201212; t=1456256570; bh=j0B2pfWNxET+1ofhsQ/2bwFJXiATHKonMJyG4NuGEc4=; h=Subject:To:References:From:Date:In-Reply-To:From; b=CLF3Jy8uz8IiD1KMT/JO8Hg+Rd2IkUmrCaHtezOr6CkXqEVPmVYZs/WgCZPWNHBSc CYLBkrK4MTRtopYBdQdS0UEkGPokE34o/cPttlW2rqv3YdfnZTfTJ1RN9fahA5eE1A TPt4ADnRVA3TX8a+eo2RDCSSsHGJZ1fiqD1X0RtQ=
In-Reply-To <CALwzidnBqeBaa=2PhyyMjehabrnLo9R1Jk5LnGfd=mEWTrd=yQ@mail.gmail.com>
X-purgate clean
X-purgate This mail is considered clean (visit http://www.eleven.de for further information)
X-purgate-type clean
X-purgate-Ad Categorized by eleven eXpurgate (R) http://www.eleven.de
X-purgate This mail is considered clean (visit http://www.eleven.de for further information)
X-purgate clean
X-purgate-size 2091
X-purgate-ID 154282::1456256570-00003BBD-92135998/0/0
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.21rc2
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Xref csiph.com comp.lang.python:103415

Show key headers only | View raw


On 23.02.2016 18:37, Ian Kelly wrote:
> It's not entirely clear to me what the C++ is actually doing. With
> Python we have an explicit event loop that has to be started to manage
> resuming the coroutines. Since it's explicit, you could easily drop in
> a different event loop, such as Tornado or curio, if desired. If your
> coroutine never awaits anything that isn't already done then
> technically you don't need an event loop, but at that point you might
> as well be using ordinary functions.

I don't think taking the shortcut to ordinary functions will work on the 
big scale.

I certainly agree that asynchronous operations can/should? be the very 
core of everything (files, sockets, timers, etc.); just as Microsoft is 
pushing with their Windows API. Chaining async ops together just works 
now with async/await in Python as well. However, in the end of the 
chaining there'll always be synchronous code that e.g. initializes the 
event loop. Real world code works the same.

Imagine, in some near/distant future, Python might have all its core 
components (like reading a file, etc. etc.) converted to async. It would 
be great for many larger applications if there one could introduce async 
gently. So, laying out an async foundation (the building blocks) but the 
wiring synchronous operations still work as they should. Once, the team 
decides they want to leverage the async potential in their code (as the 
building blocks COULD be executed concurrently), they will then be able 
to replace the synchronous wires with an event loop.

So, I see quite some potential here.

> The C++ on the other hand seems to be doing something implicit at the
> compiler level to make everything happen automatically inside the
> future.get() call, but I don't know what that is.
>
> You could wrap up the boilerplate in Python if you like:
>
> def get(coro, loop=None):
>      if loop is None:
>          loop = asyncio.get_event_loop()
>      return loop.run_until_complete(coro)
>
> print(get(tcp_reader(1000)))

As usual. :)

Best,
Sven

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

How the heck does async/await work in Python 3.5 Mark Lawrence <breamoreboy@yahoo.co.uk> - 2016-02-17 22:08 +0000
  Re: How the heck does async/await work in Python 3.5 Steven D'Aprano <steve@pearwood.info> - 2016-02-20 13:36 +1100
    Re: How the heck does async/await work in Python 3.5 Rustom Mody <rustompmody@gmail.com> - 2016-02-19 21:24 -0800
      Re: How the heck does async/await work in Python 3.5 Rustom Mody <rustompmody@gmail.com> - 2016-02-19 21:34 -0800
        Re: How the heck does async/await work in Python 3.5 Paul Rubin <no.email@nospam.invalid> - 2016-02-19 22:44 -0800
          Re: How the heck does async/await work in Python 3.5 Steven D'Aprano <steve@pearwood.info> - 2016-02-21 18:17 +1100
            Re: How the heck does async/await work in Python 3.5 Paul Rubin <no.email@nospam.invalid> - 2016-02-20 23:34 -0800
      Re: How the heck does async/await work in Python 3.5 Ian Kelly <ian.g.kelly@gmail.com> - 2016-02-20 00:48 -0700
      Re: How the heck does async/await work in Python 3.5 Chris Angelico <rosuav@gmail.com> - 2016-02-20 18:57 +1100
      Re: How the heck does async/await work in Python 3.5 Ian Kelly <ian.g.kelly@gmail.com> - 2016-02-20 01:14 -0700
      Re: How the heck does async/await work in Python 3.5 Chris Angelico <rosuav@gmail.com> - 2016-02-20 19:49 +1100
      Re: How the heck does async/await work in Python 3.5 Ian Kelly <ian.g.kelly@gmail.com> - 2016-02-20 02:11 -0700
      Re: How the heck does async/await work in Python 3.5 Ian Kelly <ian.g.kelly@gmail.com> - 2016-02-20 02:21 -0700
    Re: How the heck does async/await work in Python 3.5 Christian Gollwitzer <auriocus@gmx.de> - 2016-02-20 07:53 +0100
      Re: How the heck does async/await work in Python 3.5 "Sven R. Kunze" <srkunze@mail.de> - 2016-02-22 23:16 +0100
      Re: How the heck does async/await work in Python 3.5 Ian Kelly <ian.g.kelly@gmail.com> - 2016-02-22 17:48 -0700
      Re: How the heck does async/await work in Python 3.5 "Sven R. Kunze" <srkunze@mail.de> - 2016-02-23 17:50 +0100
      Re: How the heck does async/await work in Python 3.5 Ian Kelly <ian.g.kelly@gmail.com> - 2016-02-23 10:37 -0700
      Re: How the heck does async/await work in Python 3.5 "Sven R. Kunze" <srkunze@mail.de> - 2016-02-23 20:42 +0100
      Re: How the heck does async/await work in Python 3.5 "Sven R. Kunze" <srkunze@mail.de> - 2016-02-23 22:05 +0100
      Re: [Python-ideas] How the heck does async/await work in Python 3.5 "Joao S. O. Bueno" <jsbueno@python.org.br> - 2016-02-23 18:25 -0300
      Re: [Python-ideas] How the heck does async/await work in Python 3.5 Paul Moore <p.f.moore@gmail.com> - 2016-02-24 09:59 +0000
      Re: [Python-ideas] How the heck does async/await work in Python 3.5 Victor Stinner <victor.stinner@gmail.com> - 2016-02-24 11:01 +0100
      Re: [Python-ideas] How the heck does async/await work in Python 3.5 王珺 <wjun77@gmail.com> - 2016-02-24 18:40 +0800
        Re: [Python-ideas] How the heck does async/await work in Python 3.5 Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2016-02-25 10:00 +1300
          Re: [Python-ideas] How the heck does async/await work in Python 3.5 王珺 <wjun77@gmail.com> - 2016-02-25 08:40 +0800
          Re: [Python-ideas] How the heck does async/await work in Python 3.5 Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2016-02-24 20:37 -0500
      Re: [Python-ideas] How the heck does async/await work in Python 3.5 Tem Pl <rtempl31@gmail.com> - 2016-02-24 06:39 -0800
        Re: [Python-ideas] How the heck does async/await work in Python 3.5 Marko Rauhamaa <marko@pacujo.net> - 2016-02-24 17:23 +0200
          Re: [Python-ideas] How the heck does async/await work in Python 3.5 Ian Kelly <ian.g.kelly@gmail.com> - 2016-02-24 08:41 -0700
            Re: [Python-ideas] How the heck does async/await work in Python 3.5 Marko Rauhamaa <marko@pacujo.net> - 2016-02-24 18:13 +0200
              Re: [Python-ideas] How the heck does async/await work in Python 3.5 Ian Kelly <ian.g.kelly@gmail.com> - 2016-02-24 09:47 -0700

csiph-web