Issue with ExtInt callback and snapshot

Hi all,

I am basically trying to have a triggered snapshot.
For this, I use et ExtInt set up on a rising edge of an IO (feed by my Arduino), then inside my callback func, I take a snapshot.
In other words:

def callback(line):
    global img
    img = sensor.snapshot()
extint = pyb.ExtInt(Pin('P1'), pyb.ExtInt.IRQ_RISING, pyb.Pin.PULL_NONE, callback)

However I get a “MemoryError: memory allocation failed, heap is locked”, and as far as I understand, it seems that the snapshot call is allocating some memory, which is forbidden in the ExtInt callback function.

I wonder why the snapshot call do allocate any memory, and if there is a workaround to make this work.
Many thanks,

The snapshot call allocates memory for the return object (the image). Memory allocation is not allowed in interrupts because it might corrupt the heap if it’s being scanned or collected. An easy workaround is to set a flag in the IRQ handler and check that flag in the main loop.

Oh I should have think twice…
Thank you for your answer!