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

Nick Coghlan ncoghlan at gmail.com
Fri Apr 3 15:18:15 CEST 2009

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)


Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia

More information about the Python-ideas mailing list