how to re-init the Python execution environment

C programming, build, interpreter/VM.
Target audience: MicroPython Developers.
Post Reply
Posts: 629
Joined: Thu Sep 07, 2017 8:57 pm

how to re-init the Python execution environment

Post by jickster » Tue Dec 19, 2017 9:48 pm

What functions - and what does each do - do I need to call to "reset" the execution environment?

Let's say I've executed a bunch of REPL lines and now I want to execute a frozen script; how do I make the execution environment pristine?

2. the heap

Do I zero-out these structures? mp_init()?

Posts: 230
Joined: Tue Aug 09, 2016 10:58 am

Re: how to re-init the Python execution environment

Post by cefn » Tue Jan 02, 2018 7:46 am

Do you have a reason to avoid the following invocation...

Code: Select all

import machine
...or are you just curious if it cleanup can be done without a reset by manipulating in-memory structures?

My suspicion is there are implicitly aspects of the python language, such as imports being a one-way street (once imported, entries in the symbol table always there) which require a reset of the interpreter to really clean up. This is what the reset() function is intended for.

Note, a soft reset via machine.reset() is not quite the same as a hard reset which resets all the hardware subsystems of the board, not just the interpreter. This is an even more 'pristine' starting point. A hard reset can be done by power-cycling (unplugging and replugging USB power to a board) or potentially by pulsing your own reset pin, with a wire from a GPIO to RST as described [here](viewtopic.php?t=3582#p20789)

Post Reply