On 4/2/09, Steven D'Aprano <steve@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. -jJ