Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #103249
| 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 01:14:48 -0700 |
| Lines | 41 |
| Message-ID | <mailman.15.1455956130.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> <CALwzidnVrNmhbRhkoiCkwZbqw+7h8gd_TY5HLUMNs1ROcHzQhQ@mail.gmail.com> <CAPTjJmoFiPtoo7oNopUqsrsQJhZWySA_hGEXbuXbQxKgmPh44A@mail.gmail.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=UTF-8 |
| X-Trace | news.uni-berlin.de ETSlE4+6bz+t3HsaaheaIANbZZeeYJ1cNumupWuUe2Yg== |
| 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.002 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'received:209.85.223': 0.03; 'subject:Python': 0.05; 'exception.': 0.07; 'subject:How': 0.09; '__future__': 0.09; 'imports': 0.09; 'none.': 0.09; 'propagate': 0.09; 'exception': 0.13; 'def': 0.13; 'skip:f 30': 0.15; "%r'": 0.16; "(it's": 0.16; '12:57': 0.16; '2016': 0.16; 'async': 0.16; 'iterator,': 0.16; 'iterator.': 0.16; 'nudge': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'runtimeerror': 0.16; 'surprising': 0.16; 'wrote:': 0.16; 'work,': 0.21; 'suppose': 0.22; 'am,': 0.23; 'defined': 0.23; 'feb': 0.23; 'sat,': 0.23; 'import': 0.24; 'header:In-Reply-To:1': 0.24; "doesn't": 0.26; 'chris': 0.26; 'equivalent': 0.27; 'separate': 0.27; 'question': 0.27; 'message-id:@mail.gmail.com': 0.27; 'mind,': 0.29; 'pep': 0.29; 'subject:/': 0.30; 'work.': 0.30; 'code': 0.30; 'becomes': 0.30; 'supposed': 0.31; 'another': 0.32; 'generally': 0.32; 'point': 0.33; 'raising': 0.33; 'file': 0.34; 'gets': 0.35; 'received:google.com': 0.35; 'fresh': 0.35; 'returning': 0.35; 'but': 0.36; 'should': 0.36; 'instead': 0.36; 'there': 0.36; 'received:209.85': 0.36; 'subject:work': 0.36; 'to:addr:python-list': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'really': 0.37; 'being': 0.37; 'desired': 0.37; 'received:209': 0.38; 'subject:the': 0.39; 'to:addr:python.org': 0.40; 'still': 0.40; 'future': 0.60; 'save': 0.60; 'behavior': 0.61; '20,': 0.66; 'future,': 0.70; 'special': 0.73; 'yourself': 0.73; 'await': 0.76; 'awaited': 0.84; 'discussion)': 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=2csMpgJoLz3j+90yKkB+mMegZzKI5zA94S2wXeqj454=; b=UkzTrh1V64YqlWLDzaLseZ8A/AAxU57LbOnVzhLl3l0Vo5uECO0vO4tjkE5ruQ48Zh YP3R5cMW9s+hDDpORPbT13A62N9eP8Daqk43kawHd3QLuZjzENothQS7JJKBV+Jbs3a2 6grwx4CroiRW+9zyXTneWmEWScJneFmH8/rkzYNTirtP5//h8PYY/rFTrJGCC7iX24JG UtEwBRicV8VY5+12WQEfxmDKywAlF8c+/3wc+6DD6cD/TjFVetqTRTmplkB64RKt3Z5J 68pmIyWvzJAy6CrDnfibBAS2NJ6FZlIvxdM0IzFb9c8jNfuGz8KQbxfstjjkoX2m8AXH mrOA== |
| 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=2csMpgJoLz3j+90yKkB+mMegZzKI5zA94S2wXeqj454=; b=ZWibegOPVEjrkAuPJUVoIuDgif/H7oyDWB2w249HKktk5jroiuLNh3QPmLWOotUkR6 7TqnjOT/sWJwziToGjNtD1c+gHIHp0wDlCJ9bEfCRdqk6iQUvQICNegchQsJUnvc6LtE uNd9sXbjH3OmfCLDromQKNrJRSxTc190w2+7wbbZqz+Tw1OFEiuFlMRPlqrygaV3SVUq G8lzCQFoyFLzOD6Sq5EAQhOpkoDpJ4F+nB4eI/h9B+q3cTPhyC9oADWLwQRX4pkTaPWn c2p1KFnt91y97dUPRKysPD95aa+K5NyI+TZt9WytF2DuNdT73hB+n1xv0aqMKQ9Ap22k RhKA== |
| X-Gm-Message-State | AG10YOS81ipsXIBLKxswrqvMdcSdeKnCcAxyxdcOiAz4xRxC7ZK5yNRksMsk+eQMuSciwN5xfiBYS43W4PoefA== |
| X-Received | by 10.107.19.90 with SMTP id b87mr20759724ioj.11.1455956128058; Sat, 20 Feb 2016 00:15:28 -0800 (PST) |
| In-Reply-To | <CAPTjJmoFiPtoo7oNopUqsrsQJhZWySA_hGEXbuXbQxKgmPh44A@mail.gmail.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:103249 |
Show key headers only | View raw
On Sat, Feb 20, 2016 at 12:57 AM, Chris Angelico <rosuav@gmail.com> wrote:
> On Sat, Feb 20, 2016 at 6:48 PM, Ian Kelly <ian.g.kelly@gmail.com> wrote:
>> 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.
>
> Solved by PEP 479. Use "from __future__ import generator_stop" to save
> yourself the pain.
Nope.
py> from __future__ import generator_stop
py> import asyncio
py> async def test_coro():
... fut = asyncio.Future()
... fut.set_exception(StopIteration())
... print('received %r' % await fut)
...
py> list(test_coro().__await__())
received None
[]
I think because __future__ imports are per-file, and
asyncio.Future.__iter__ is defined in a file outside my control that
doesn't have the __future__ import.
I suppose that when the generator_stop behavior becomes standard then
it will work, but still that will just cause a RuntimeError to
propagate instead of the desired StopIteration.
It's not really that big a deal since there is a code smell to it, but
it's surprising since intuitively StopIteration should have no special
meaning to a PEP 492 coroutine (it's not an iterator, wink wink, nudge
nudge), and the thing being awaited is a Future, which also doesn't
intuitively look like an iterator. Note that if you just call
Future.result(), then the exception propagates as expected; it's just
awaiting it that doesn't work.
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll 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