This project has moved and is read-only. For the latest updates, please go here.

GeneratorExit exception when running under PyTools

Jul 27, 2011 at 8:42 PM

This is my code:

def memoize(f):
    cache = dict()
    def memof(x):
        try: return cache[x]
            cache[x] = f(x)
            return cache[x]
    return memof

n,m = 8,3
init = frozenset((x,y) for x in range(n) for y in range(m))

def moves(board):
    return [frozenset((x,y) for (x,y) in board if x < px or y < py) for px,py in board]

def wins(board):
    if not board: return True
    return any(not wins(move) for move in moves(board))

print wins(init)

When running this in Python 2.6 or 2.7 under PyTools I get a GeneratorExit exception. When running it with IronPython in PyTools or in Python from the console I do not get an exception. What am I doing wrong?


Jul 27, 2011 at 10:04 PM

Nothing; CPython is using GeneratorExit as a control flow exception; arguably we should not break on unhandled GeneratorExit by default.

You can stop PyTools from breaking on GeneratorExit by going to Debug->Exceptions->Python Exceptions and unchecking GeneratorExit in the list. In general, if the debugger is breaking on an exception which you would like to ignore, you can click "Break" in the exception dialog box, then go to Debug->Exceptions->Python Exceptions and uncheck that exception.  Then hit F5 to continue and you won't break on those exceptions any more.