Author stestagg
Recipients stestagg, xxm
Date 2020-12-29.16:06:13
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1609257973.35.0.0724631234108.issue42762@roundup.psfhosted.org>
In-reply-to
Content
I'm sorry, I did get a bit confused earlier, I'd mentally switched to context managers.

I agree this is a bug, and a kinda weird one!

I've narrowed it down to this:

If an exception causes flow to exit a for-loop that's powered by a generator, then when the generator object is deleted, GeneratorExit() is incorrectly raised in the generator.

This can be shown with the following example (easier to debug without the infinite loop):

---
def foo():
    try:
        yield
    except:
        print("!!! WE SHOULDN'T BE HERE!!!")

x = foo()
try:
    for _ in x:
       print(i)
except NameError:
    pass 

print("LOOP DONE")
del x   # <--- We shouldn't be here printed on this line.
print("FINAL")
---

As you discovered, if you change print(i) to print(1), then the "shouldn't be here" line is NOT printed, but if you leave it as print(i) then the exception is printed.

You can see that the error doesn't happen until after LOOP DONE, which is because `del x` is finalizing the generator object, and the invalid exception logic happens then.

I'm trying to get more info here, if I don't by the time you come online, I'd recommend creating a *new* issue, with the non-loop example above, and explanation because I think on this issue, I've caused a lot of noise (sorry again!).
History
Date User Action Args
2020-12-29 16:06:13stestaggsetrecipients: + stestagg, xxm
2020-12-29 16:06:13stestaggsetmessageid: <1609257973.35.0.0724631234108.issue42762@roundup.psfhosted.org>
2020-12-29 16:06:13stestagglinkissue42762 messages
2020-12-29 16:06:13stestaggcreate