[Python-ideas] Yield-From: Handling of GeneratorExit
jimjjewett at gmail.com
Sat Apr 4 00:10:55 CEST 2009
On 4/2/09, Steven D'Aprano <steve at pearwood.info> wrote:
> On Fri, 3 Apr 2009 11:18:25 am 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?
generators are trickier, so I would say yes, except that ...
Someone who is already intentionally catching and ignoring an
Exception may not be in the mood to respond to subtle hints.
> Perhaps I've missed something, but it seems to me that the right limit
> to use would be the recursion limit, and the right exception to raise
> would be RecursionError rather than RuntimeError.
The recursion limit is normally a way to prevent memory exhaustion.
In this case, the stack doesn't grow; it is still a generic "while
True: pass" that just happens to bounce between two frames instead of
sticking to one.
More information about the Python-ideas