[Python-ideas] Yield-From: Handling of GeneratorExit

Guido van Rossum guido at python.org
Fri Apr 3 19:22:17 CEST 2009


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.

-- 
--Guido van Rossum (home page: http://www.python.org/~guido/)



More information about the Python-ideas mailing list