Welcome to the Pycom forum Forum
    • \[\[global:header.categories\]\]
    • \[\[global:header.recent\]\]
    • \[\[global:header.tags\]\]
    • \[\[global:header.popular\]\]
    • Login

    Explore Pybytes | Official Documentation | Report a Firmware Bug/Issue | GitHub

    .py .mpy python cache?

    Scheduled Pinned Locked Moved Discussion
    wipyoemupgrade
    5 Posts 2 Posters 706 Views 4 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • T Offline
      thibault
      last edited by

      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 a it's the a.py will be loaded.

      So we have delete all .py (but not main.py and boot.py) and reset the card. We get 22 seconds of start time.

      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.

      Thank's

      robert-hhR 1 Reply Last reply Reply Quote 1
      • robert-hhR Offline
        robert-hh @thibault
        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.

        1 Reply Last reply Reply Quote 0
        • T Offline
          thibault
          last edited by

          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-hhR 1 Reply Last reply Reply Quote 0
          • robert-hhR Offline
            robert-hh @thibault
            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.

            T 1 Reply Last reply Reply Quote 0
            • T Offline
              thibault @robert-hh
              last edited by

              @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!

              1 Reply Last reply Reply Quote 0

              Hello! It looks like you're interested in this conversation, but you don't have an account yet.

              Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

              With your input, this post could be even better 💗

              Register Login
              • 1 / 1
              • First post
                Last post

              Pycom on Twitter

              Pycom