adafruit / circuitpython

CircuitPython - a Python implementation for teaching coding with microcontrollers
https://circuitpython.org
Other
4.1k stars 1.22k forks source link

Board freeze on generator.close() #7565

Closed gelsrc closed 1 year ago

gelsrc commented 1 year ago

CircuitPython version

8.0.0 on Waveshare RP2040-Zero
8.0.0 on Luatos Core ESP32C3

Code/REPL

#
# This code freeze the board when run after second REPL restart / after code.py autoreload
#
def gen():
    while True:
        yield 0

while True:
    g = gen()
    print(next(g))
    g.close()

Behavior

The bug occurs after restarting the Python machine. Just after reset / boot code works well. The second run freeze the board.

Description

I checked this on two different boards: Waveshare RP2040-Zero and Luatos Core ESP32C3. The bug is 100% reproduciable.

Some test results:

Additional information

No response

gelsrc commented 1 year ago

It looks like the bug related with f3169246b, b499275bb.

When I build 8.0.0 with MICROPY_CPYTHON_EXCEPTION_CHAIN=0 the freeze is gone.

jepler commented 1 year ago

Thanks, that's excellent information @gelsrc !

jepler commented 1 year ago

I don't think it's a micropython core issue, as they haven't (to my knowledge) taken the chained-exception patch, nor do they reset the VM the way we do

tannewt commented 1 year ago

I meant our "micropython core". Maybe we need to use an upstream tag in addition to this one.

dhalbert commented 1 year ago

Fixed by #7566.