Path: csiph.com!optima2.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!1.eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed7.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.079 X-Spam-Evidence: '*H*': 0.84; '*S*': 0.00; '"""': 0.05; 'generators': 0.09; 'here?': 0.09; 'methods,': 0.09; 'python': 0.10; 'async': 0.16; 'coroutines': 0.16; 'foo()': 0.16; 'foo():': 0.16; 'wrote:': 0.16; 'basically': 0.18; 'implementing': 0.18; '2015': 0.20; 'developer': 0.20; 'for?': 0.23; 'this:': 0.23; 'import': 0.24; 'header:In-Reply-To:1': 0.24; 'equivalent': 0.27; 'message- id:@mail.gmail.com': 0.27; 'yield': 0.27; 'function': 0.28; 'blocking': 0.29; 'invoke': 0.29; 'javier': 0.29; "i'm": 0.30; "can't": 0.32; 'knows': 0.32; 'non': 0.32; 'maybe': 0.33; 'foo': 0.33; 'tue,': 0.34; 'this?': 0.34; 'received:google.com': 0.35; 'something': 0.35; 'but': 0.36; 'should': 0.36; 'there': 0.36; 'to:addr:python-list': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'doing': 0.38; 'stuff': 0.38; 'data': 0.39; 'does': 0.39; 'to:addr:python.org': 0.40; 'still': 0.40; 'waiting': 0.60; 'no.': 0.62; 'yes': 0.62; 'skip:n 10': 0.62; 'more': 0.63; 'everybody': 0.67; 'capabilities': 0.72; 'jul': 0.72; 'await': 0.76; 'lack': 0.76; '"yield': 0.84; 'flexible,': 0.84; 'from"': 0.84; 'subject:Send': 0.84; 'to:name:python': 0.84; 'from.': 0.93 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=JGpW4gDxAlVJ83iALRU+QrJ2bZnwRLk594Mkstj980c=; b=o0H7jMr2/VXUSEBYFB3pVw/d4xoLtBubbwn3VFnHvoXYl5QERdk1Zb1dTHUcjprWG9 LXPaG0s0AEwQjVHWPoGp+PN6dwc7huFD/Z1OWx1jl5GItimRz7HaS+Xf+DGWslCLwhKO soiH/L0fyePVMqwdPBvRbT7Q+wbDwEdepyjcv0N7uEpkcW5hfH5IeDhzQhtvenuvvndg ivWePnKf5fJnkXfTkf10qNzA6Ijb7EuSQdzuMt8jW0L9dc5Xh50bzdaGHbnUcQPLEETY liCe+lL65kV6WWxCKGYV3ezInptoQxg2vVLJu5pawlvI7avUoJW4ca+crQl+1RVSkdJn v1Ng== X-Received: by 10.107.41.11 with SMTP id p11mr54660812iop.148.1438125666921; Tue, 28 Jul 2015 16:21:06 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: References: <97b62bfd-8b6d-45f0-8597-7799ba0ea4af@googlegroups.com> <1195c0a3-05b5-4213-92a7-db005ad7d547@googlegroups.com> From: Ian Kelly Date: Tue, 28 Jul 2015 15:20:27 -0800 Subject: Re: Send data to asyncio coroutine To: Python Content-Type: text/plain; charset=UTF-8 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 33 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1438131695 news.xs4all.nl 2836 [2001:888:2000:d::a6]:40015 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:94712 On Tue, Jul 28, 2015 at 2:41 PM, Javier wrote: > I think that force the developer to 'yield from' all function calls to keep async capabilities is a big mistake, it should be more flexible, like this: > > import asyncio > > @asyncio.coroutine > fun non_blocking_io(): > """ Everybody knows I'm doing non blocking IO """ > ... > > fun foo(): > """ I invoke functions that do IO stuff """ > data = yield from non_blocking_io() > yield from store_data_db(data) > ... > > fun bar(): > """ I don't know what foo implementation does """ > foo() > > asyncio.async(bar()) Do you have a proposal for implementing this? What does "yield from" actually do here? How does the event loop know that foo is waiting for something and what it is waiting for? > Does python 3.5 await/async solve this? Yes and no. await is basically equivalent to yield from with extra validation, so you still can't use them like what you have above. But native coroutines are also clearly not generators as they lack __next__ and __iter__ methods, so maybe there will be less temptation to try to use them without using await / yield from.