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


Groups > comp.lang.python > #103244

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

Path csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail
From Ian Kelly <ian.g.kelly@gmail.com>
Newsgroups comp.lang.python
Subject Re: How the heck does async/await work in Python 3.5
Date Sat, 20 Feb 2016 00:48:31 -0700
Lines 45
Message-ID <mailman.13.1455954554.13884.python-list@python.org> (permalink)
References <mailman.224.1455746935.22075.python-list@python.org> <56c7d145$0$1597$c3e8da3$5496439d@news.astraweb.com> <9d968a2e-f23c-4c93-979d-43dfa610c343@googlegroups.com>
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8
X-Trace news.uni-berlin.de ZzvOJoQGrdGcngr79RpXhAMwCoGU17EOckIqUHwzF7gw==
Return-Path <ian.g.kelly@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.001
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'received:209.85.223': 0.03; 'subject:Python': 0.05; 'method.': 0.05; 'exception.': 0.07; 'subject:How': 0.09; 'abstraction': 0.09; 'generators': 0.09; 'iterate': 0.09; 'none.': 0.09; 'propagate': 0.09; 'semantics': 0.09; 'underlying': 0.09; 'exception': 0.13; 'def': 0.13; "*isn't*": 0.16; '2016': 0.16; 'coroutines': 0.16; 'entirely.': 0.16; 'generators.': 0.16; "guido's": 0.16; 'iterable': 0.16; 'iteration.': 0.16; 'iterator': 0.16; 'iterator.': 0.16; 'mistake.': 0.16; 'nevertheless': 0.16; 'overloaded': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'symmetric': 0.16; 'wrote:': 0.16; '2001': 0.18; 'basically': 0.18; "aren't": 0.22; 'greg': 0.22; 'minor': 0.22; 'rid': 0.22; 'feb': 0.23; 'implemented': 0.24; 'thus': 0.24; 'header:In-Reply-To:1': 0.24; "doesn't": 0.26; 'sense': 0.26; 'equivalent': 0.27; 'fri,': 0.27; 'separate': 0.27; 'question': 0.27; 'message-id:@mail.gmail.com': 0.27; 'looks': 0.29; 'mind,': 0.29; 'pep': 0.29; 'subject:/': 0.30; 'work.': 0.30; 'supposed': 0.31; 'another': 0.32; 'implement': 0.32; 'generally': 0.32; 'language.': 0.32; 'maybe': 0.33; 'point': 0.33; 'choosing': 0.33; 'raising': 0.33; 'gets': 0.35; 'received:google.com': 0.35; 'clear': 0.35; 'fresh': 0.35; 'returning': 0.35; 'expected': 0.35; 'step': 0.36; 'but': 0.36; 'too': 0.36; 'should': 0.36; 'instead': 0.36; 'received:209.85': 0.36; 'keyword': 0.36; 'subject:work': 0.36; 'to:addr:python- list': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'two': 0.37; 'received:209': 0.38; 'wrong': 0.38; 'subject:the': 0.39; 'rather': 0.39; 'to:addr:python.org': 0.40; 'still': 0.40; 'future': 0.60; 'ever': 0.60; 'hope': 0.61; 'skip:n 10': 0.62; 'more': 0.63; 'great': 0.63; 'series': 0.65; "they're": 0.66; 'future.': 0.67; 'future,': 0.70; 'sound': 0.72; '"yield': 0.84; 'complaint': 0.84; 'discussion)': 0.84; 'distinguish': 0.84; 'down:': 0.84; 'from"': 0.84; 'to:name:python': 0.84; 'awaiting': 0.91
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=G9LdTX1qtyonzWkGoMNpRPOLipNf1do0687uE2WJMmk=; b=aFvw26RyOlTPDvqNSg6HzDSaw88JEDTBIV/QftcGwGLECOPGiZkyP52+XRukN3t5U8 ULhn6f1JE76J3TKrTpKe/FWey4D3YWDMEdAO3WpOmUud3Jznuxi3V3QxloSYtve5wU6F lg3rxXpI3kS9ZI/EJaft0z0LLNx8TKvGAra6odbu8n9gGDZn2Cc2Y4as11iNA0nKkcEg RkyPAS7uvbjes5fpmnKrW3Rtz/tFANHDPclxjE+R6VOJxFsMqjpcaWZIdSHj6Zvhat/9 2wpxUQS+/lzbUbM24WQkjPtFq5eVifRKJXDHZCVcn12FcU+Y1C2ZFGp8ZF31QBdZ6J80 x5Qg==
X-Google-DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:content-type; bh=G9LdTX1qtyonzWkGoMNpRPOLipNf1do0687uE2WJMmk=; b=c/2ssA2ZHN5Sgj/YDKtnVfeTkwBX0wJczzS1DO95a7fMgDJWBbSMUIuWHOiiaXbt0d dWNZ8Og7GhiOqSSIcUxlbflv8RAOPTPD73b0qqV70Wet9dzGhx/mlG3sUlVzeDCAzSYN wbbiavEh/FWcGVHov9mUBrmnEBvMZAmMyayCMc5wdD5ly2sYKQZmZ4BmlIlIjXvcGWSL uwmOxFslvr6RGkhCgCMlPpNa3s9GctfZq4jaTEwpntBmt8eNJNG488v5NyDbK/9vddzj rVhDqqVh0szyM338RhszeupXnSmGVbZAEu2bWUzct+MoK2hcyWTQtwvTh5WBJKIAmNsl wvmQ==
X-Gm-Message-State AG10YOQzStllnPaef6SvwXvIRbpxMn4gZEqR0oq2S664dki0Pgs0NI0V+nqF67Eb8SLPs+eTQUeVEOZjRvB5gQ==
X-Received by 10.107.185.214 with SMTP id j205mr18890535iof.111.1455954551159; Fri, 19 Feb 2016 23:49:11 -0800 (PST)
In-Reply-To <9d968a2e-f23c-4c93-979d-43dfa610c343@googlegroups.com>
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:103244

Show key headers only | View raw


On Fri, Feb 19, 2016 at 10:24 PM, Rustom Mody <rustompmody@gmail.com> wrote:
> Less snarkily looks like a series of bolt-ons after bolt-ons
>
> IMHO Guido's (otherwise) uncannily sound intuitions have been wrong right from
> 2001 when he overloaded def for generators.
> And after that its been slippery-slope down: reusing generator-yield (statement)
> for coroutine-yield (expression)
> Most recently choosing these async-await keywords instead of the more symmetric
> suggestions of Greg Ewing

Two out of three of those are fine. IMO generators should have
required a separate keyword to distinguish them from ordinary
functions, but it's a minor complaint and they're otherwise a great
addition to the language.

I do think it's pretty clear at this point though that PEP 342 was a
mistake. We should never have introduced generator-based coroutines;
it's an abstraction with too much leakage. It doesn't make sense that
generator-based coroutines implement the iterator protocol, because
there's no reason to ever try to iterate over them. It also doesn't
make sense to ever iterate over a Future, and yet asyncio Futures,
which aren't even coroutines, are nevertheless *forced* to be iterable
just because that's how coroutines work. Otherwise you couldn't "yield
from" a Future.

As another point that happens to be fresh in my mind, awaiting a
Future on which an exception gets set is supposed to propagate the
exception. I recently found that this breaks if the exception in
question happens to be StopIteration (granted not one that should
generally be allowed to propagate anyway, but that's a separate
discussion) for the simple reason that raising StopIteration in a
generator is equivalent to returning None. The awaiting coroutine thus
gets a non-exceptional result of None rather than the expected
exception. The irritating thing to me is that this even plagues PEP
492 coroutines using "await" rather than "yield from", because the two
are basically the same under the covers. The former gets an iterator
by calling __await__ instead of __iter__, but it's still implemented
using an iterator. If you look at the asyncio.Future implementation,
__await__ is actually just a synonym of the __iter__ method.

My hope is that someday we can get rid of PEP 342 coroutines entirely.
Then maybe we can get a coroutine implementation that's actually sane.
PEP 492 with async/await and non-iterable semantics is a step in the
right direction, but ultimately I think we also need an underlying
implementation that *isn't* fundamentally based on iteration.

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