Frozen bytecode main.py
Posted: Wed Aug 15, 2018 6:47 am
I am on production phase and would like to froze main.py and other modules into the micropython binary file, so after it burned into flash it will run directly. is this possible?
Please see the new forum at
https://forum.micropython.org/
Ok, so in short, after adding my main.py in "modules" directory, and then by modify the _boot.py by add "import main.py" line at below is enough?Roberthh wrote: ↑Wed Aug 15, 2018 7:15 amThe resepctive code is around https://github.com/micropython/micropyt ... main.c#L68
There you see, that a file called _boot.py is run from flash, and that boot.py and main.py are run form the file system. You can either change the call for boot.py and main.py into pyexec_frozen_module(), or put the start of your modules into _boot.py.
Code: Select all
import gc
gc.threshold((gc.mem_free() + gc.mem_alloc()) // 4)
import uos
from flashbdev import bdev
try:
if bdev:
uos.mount(bdev, '/')
except OSError:
import inisetup
inisetup.setup()
gc.collect()
import main.py
Code: Select all
import gc
gc.threshold((gc.mem_free() + gc.mem_alloc()) // 4)
import uos
from flashbdev import bdev
try:
if bdev:
uos.mount(bdev, '/')
except OSError:
import inisetup
inisetup.setup()
try:
uos.stat('/main.py')
except OSError:
with open("/main.py", "w") as f:
f.write("""\
import mqtt
""")
gc.collect()