c# async, await
Terry Reedy
tjreedy at udel.edu
Thu Aug 22 19:04:32 EDT 2013
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
More information about the Python-list
mailing list