Path: csiph.com!usenet.pasdenom.info!news.albasani.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.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.003 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'explicitly': 0.05; 'level,': 0.07; 'callback': 0.09; 'generators': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'url:archive': 0.09; 'url:blog': 0.10; 'python': 0.11; 'def': 0.12; 'gui': 0.12; 'jan': 0.12; '2.2,': 0.16; 'evening,': 0.16; 'iterable:': 0.16; 'iterator': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'reedy': 0.16; 'terribly': 0.16; 'value;': 0.16; '});': 0.16; 'language': 0.16; 'wrote:': 0.18; 'discussion': 0.18; "python's": 0.19; 'written': 0.21; 'example': 0.22; 'programming': 0.22; '(in': 0.22; 'header:User-Agent:1': 0.23; '(by': 0.24; 'certainly': 0.24; 'library,': 0.24; 'replace': 0.24; 'task': 0.26; 'this:': 0.26; 'values': 0.27; 'header:X -Complaints-To:1': 0.27; 'header:In-Reply-To:1': 0.27; 'michael': 0.29; 'am,': 0.29; 'tim': 0.29; "i'm": 0.30; '(since': 0.31; 'libraries': 0.31; 'values.': 0.31; 'this.': 0.32; 'probably': 0.32; 'but': 0.35; 'there': 0.35; "he's": 0.36; 'himself': 0.36; 'library.': 0.36; 'url:org': 0.36; 'level': 0.37; 'to:addr:python- list': 0.38; 'fact': 0.38; 'anything': 0.39; 'does': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'days': 0.60; 'hope': 0.61; 'introduced': 0.61; 'son': 0.61; 'new': 0.61; 'received:173': 0.61; 'myself': 0.63; 'sum': 0.64; 'more': 0.64; 'url:v': 0.71; 'url:youtube': 0.71; 'await': 0.74; 'lowest': 0.74; 'url:watch': 0.77; 'asynchronous': 0.84; 'nice,': 0.84; 'protocol,': 0.84; 'received:fios.verizon.net': 0.84; 'url:2013': 0.84; 'blog,': 0.93 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Terry Reedy Subject: Re: c# async, await Date: Thu, 22 Aug 2013 19:04:32 -0400 References: <521618D4.7060000@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: pool-173-75-251-66.phlapa.fios.verizon.net User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:17.0) Gecko/20130801 Thunderbird/17.0.8 In-Reply-To: <521618D4.7060000@gmail.com> X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 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: 51 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1377212688 news.xs4all.nl 15918 [2001:888:2000:d::a6]:46129 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:52853 On 8/22/2013 9:57 AM, Michael Torrie wrote: > On 08/22/2013 05:29 AM, Neal Becker wrote: >> So my son is now spending his days on c# and .net. He's enthusiastic about >> async and await, and said to me last evening, "I don't think python has anything >> like that". I'm not terribly knowledgeable myself regarding async programming >> (since I never need to use it). I did look at this: >> >> http://tirania.org/blog/archive/2013/Aug-15.html The iterator protocol, introduced in 2.2, was explicitly intended (by Tim Peters) to replace many uses of synchonous callbacks. This example from the blog, of callback replacement, int sum_values (Hashtable hash) { int sum = 0; hash.foreach ((key, value) => { sum += value; }); return sum; } is written in Python *much more generally* as def sum(iterable): sum = 0 for item in iterable: sum += item return sum Notice that this is not limited to summing ints, nor to summing values in a hash. sum(somedic.values()) does the specific task of summing hash values. > Any time you use a GUI library, you can often use its own async > primitives (in fact you probably need to). For example glib from Gtk+ > provides io wait primitives. Or if you want a completely asynchronous > programming experience from top to bottom, you can use python twisted. > There are also other libraries to do this. > > Having first-class language support is certainly nice, and it would be > nice if Python had this. GvR himself agrees. > http://www.youtube.com/watch?v=sOQLVm0-8Yg C#'s await was part of the early discussion about Python's new asynch library. Last I knew, 'Tulip' uses callbacks at the lowest level, but the user level uses generators and 'yield from'. I hope this makes in into 3.4. -- Terry Jan Reedy