[Python-ideas] Yield-From: Handling of GeneratorExit
Nick Coghlan
ncoghlan at gmail.com
Sat Apr 4 02:45:09 CEST 2009
Guido van Rossum wrote:
> On Fri, Apr 3, 2009 at 6:18 AM, Nick Coghlan <ncoghlan at gmail.com> wrote:
>> Greg Ewing wrote:
>>> Nick Coghlan wrote:
>>>
>>>> I think I'd prefer to see some arbitrary limit (500 seems like a nice
>>>> round number) on the number of times that GeneratorExit would be thrown
>>>> before giving up
>>> Is it really worth singling out this particular way
>>> of writing an infinite loop?
>>>
>>> If you're catching GeneratorExit then you presumably
>>> have the need to clean up and exit on your mind, so
>>> I don't think this is a likely mistake to make.
>> I came up with a different answer that I like better - don't mess with
>> GeneratorExit and close() at all, and instead provide next_return(),
>> send_return() and throw_return() methods that *expect* to get a
>> GeneratorReturn exception in response (and complain if it doesn't happen).
>>
>> (I expand on this idea in a lot more detail in my reply to Jim)
>
> Since there are so many threads, let me repeat that I'm -1 on adding
> more methods, but +1 on adding them to the docs as recipes.
If we end up adding a support library for coroutines (depending on how
the discussion of the @coroutine problem goes), then that may be another
place for them.
Fattening the generator API even further bothered me a bit as well, so
I'm actually happy to be overruled on that particular idea :)
Cheers,
Nick.
--
Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia
---------------------------------------------------------------
More information about the Python-ideas
mailing list