.py .mpy python cache?
Hello, i don't know very well how to write my question:
-firstly because my english are not good
-secondly because my problem are not very clear
We use an OEM wipy in our farm product. In the first time we have use a python script with the .py extension. We measure the start time, and we get 26 seconds. In a second time, we have use a precompiled file of our script with the .mpy extension. I have checked that if a.py and a.mpy are in the filesystem, when we do
import ait's the a.py will be loaded.
In a third time, we have do a complete reset of the wipy with the following command:
pycom-fwtool-cli -v -p /dev/ttyUSB0 erase_all
and now we get a startup time of 16 seconds.
So my question are: there is a cache elsewhere wich store an old version of the script file. Or maybe anyone have an explication about this?
For now, we measure the startup time to be sure that when we do update of our product all is fine. And if not (sometimes) we do the complete reset. But i want, if possible, understand what this phenomenon.
I hope i will be a minimum clear in my description of the problem.
@robert-hh ah yes, exactly, in the 16 second time of startup i read some file: planning.txt for see if startup is needed for the device, wifi_name.txt for the device SSID etc... Not all for the code loading!
robert-hh last edited by
@thibault fo a 2000 lin script I expect a load & startup time of about a second, when loaded from a mpy file or as frozen bytecode. So if you see 16 seconds and more, then most of the time is spent not for loading the code but for executign the initial phases of the device boot (like connecting WiFi) and the code.
I'm not a good programmer, so i have write 2076 line of code actually for doing the job. I think a good programmer need less line to do the same thing. For fastly execute the code i have use mpy file, but i know that it's be possible to use the frozen bytecode to save memory. In the past i have try to compile firmware to try the encryption filesystem with success. Maybe in the future i will try the frozen code. But for now the system is fine for what we want to do.
@robert-hh It's important for me to understand what the difference in startup time i have see. But with you answer i imagine that some file will stay in memory when i delete .py file.
Thank's for you answer and tips. And have a nice day ++
robert-hh last edited by
@thibault 16 or 22 seconds import time is extremly long. It must be a very large python script, several 1000 lines of code.
Is it possible that in addition to importing also other processes are going on, like communication, external hardware init etc.
Python scripts may reside in all places listed by sys.path, e.g. in the lib directory. Maybe somthing was still there. And by erasing the flash you also create a new file system. That may be in better shape than the one you deleted.
Besides that, you can also include compiled scripts in the flash memory as frozen bytecode. Then these are not loaded, but executed in situ. That saves RAM and loading time. The only hiccupt then is, that you hav to compile your own firmware images. That's not difficult, as long as you follow the instructions literally and use a Linux system.