[Python-ideas] yield from multiple iterables (was Re: The async API of the future: yield-from)

Christian Tismer tismer at stackless.com
Sat Oct 20 14:54:00 CEST 2012


On 20.10.12 13:52, Christian Tismer wrote:
> Hi Greg,
>
> On 20.10.12 02:50, Greg Ewing wrote:
>> Christian Tismer wrote:
>>> Actually I would like to have a python context where it gets into
>>> "async mode" and interprets all functions defined in that mode as 
>>> generators.
>>
>> That sounds somewhat similar to another idea I proposed a while
>> ago:
>>
>> There would be a special kind of function called a "cofunction",
>> that you define using "codef" instead of "def". A cofunction
>> is essentially a generator, but with a special property: when
>> one cofunction calls another, the call is implicitly made as
>> a "yield from" call.
>>
>
> Whow, I had a look at the patch. Without talking about the syntax,
> this is very close to what I'm trying without a patch.
> No, it is almost identical.
>> This scheme wouldn't be completely transparent, since the
>> cofunctions have to be defined in a special way. But the calls
>> would look like ordinary calls.
>>
>> There's a PEP describing a variation on the idea here:
>>
>> http://www.python.org/dev/peps/pep-3152/
>>
>> In that version, calls to cofunctions are specially marked
>> using a "cocall" keyword. But since writing that, I've come to
>> believe that my original idea (where the cocalls are implicit)
>> was better.
>
> Yes, without the keyword it looks better. Would you raise an
> exception if something is called that is not a cofunction? Or
> would that be an ordinary call?
>
> The only difference is that I'm not aiming at coroutines in
> the first place, but just having the concept of a *suspendable*
> function.
>
> What has happened to the PEP, was it rejected?
>

I just saw that it is in flux and did not please you as well.

A rough idea would be to start the whole interpreter in suspendable
mode. Maybe that's too much. I'm seeking a way to tell a whole bunch
of functions that they should be suspendable.
What if we had a flag (unclear how) that function calls should behave
like cofunctions now. That flag would be initiated by a root call
and then propagated to the callees, without any syntax change?

In any case it should be possible to inquire/assert that a function
is running as cofunction.

-- 
Christian Tismer             :^)   <mailto:tismer at stackless.com>
Software Consulting          :     Have a break! Take a ride on Python's
Karl-Liebknecht-Str. 121     :    *Starship* http://starship.python.net/
14482 Potsdam                :     PGP key -> http://pgp.uni-mainz.de
phone +49 173 24 18 776  fax +49 (30) 700143-0023
PGP 0x57F3BF04       9064 F4E1 D754 C2FF 1619  305B C09C 5A3B 57F3 BF04
       whom do you want to sponsor today?   http://www.stackless.com/




More information about the Python-ideas mailing list