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

    MemoryErrors even with frozen modules?

    Scheduled Pinned Locked Moved Discussion
    7 Posts 2 Posters 43 Views 2 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.
    • B Offline
      BetterAuto Pybytes Beta
      last edited by BetterAuto

      I am using an unmodified copy of Pycom's GoogleIOT library including its main.py which I have renamed testmain3.py. I have frozen this code into firmware 1.20.0.rc13 (can't use anything newer due to this bug.) It's running on a WiPy2 until my 3s arrive, which shouldn't be a problem because the Google code was written when the 2.0 was still somewhat common. And I've seen this run at least once. But now it will not run at all. What gives? I thought freezing would solve this--especially for a vendor-supplied bit of code that isn't terribly complicated.

      >>> import testmain3
      Connecting to WiFi *******************
      Syncing time with time.google.com.
      Traceback (most recent call last):
        File "<stdin>", line 1, in <module>
        File "testmain3.py", line 55, in <module>
        File "umqtt.py", line 105, in connect
      MemoryError: memory allocation failed, allocating 40960 bytes
      >>>
      

      As you can see, they've been frozen:

      >>> os.listdir()
      ['boot.py', 'cert', 'config.py', 'lib', 'main.py', 'sys']
      >>> help('modules')
      MQTTClient        framebuf          struct            umqtt
      MQTTConst         gc                sys               uos
      MQTTDeviceShadow  google_iot_core   testmain          uqueue
      MQTTLib           hashlib           testmain3         ure
      MQTTMsgHandler    json              time              uselect
      MQTTShadowManager machine           ubinascii         uselect
      __main__          math              ubinascii         usocket
      _boot             micropython       ucollections      ussl
      _main             network           ucrypto           ustruct
      _thread           os                uctypes           utime
      array             pycom             uerrno            utimeq
      binascii          queue             uerrno            uzlib
      builtins          re                uhashlib          websocket
      cmath             select            uio
      crypto            socket            ujson
      errno             ssl               umachine
      Plus any modules on the filesystem
      >>>
      
      L 1 Reply Last reply Reply Quote 0
      • L Offline
        livius @BetterAuto
        last edited by

        @BetterAuto said in MemoryErrors even with frozen modules?:

        testmain3

        Frosing modules is not a magic trick. If there are dynamic structures then they reside in RAM.
        And wipy 2 have really big RAM limits.
        I fight with it long to be able to use 12 sensors and display data on ePaper 4.2 inch (400x300 px) but solved it finally.

        If yuu need to run on it something big you must split modules into parts.
        Import one part and when used unload it and go to next part. Hard work but can be done.

        think about people first, then computers

        B 1 Reply Last reply Reply Quote 0
        • B Offline
          BetterAuto Pybytes Beta @livius
          last edited by

          @livius said in MemoryErrors even with frozen modules?:

          @BetterAuto said in MemoryErrors even with frozen modules?:

          testmain3

          Frosing modules is not a magic trick. If there are dynamic structures then they reside in RAM.
          And wipy 2 have really big RAM limits.
          I fight with it long to be able to use 12 sensors and display data on ePaper 4.2 inch (400x300 px) but solved it finally.

          If yuu need to run on it something big you must split modules into parts.
          Import one part and when used unload it and go to next part. Hard work but can be done.

          Understood--but this is code supplied by Pycom two years ago when the WiPy2 was more common. And it worked once. Can't see why it wouldn't work again, especially when frozen.

          L 1 Reply Last reply Reply Quote 0
          • L Offline
            livius @BetterAuto
            last edited by livius

            @BetterAuto

            It depend what you run before this import.
            do this first:

            import gc
            print(gc.mem_free())
            gc.collect()
            print(gc.mem_free())
            

            and then try to import your module if there is 40960 bytes free.
            It should be able to import on start of the board as after reset for me it is e.g. 57264

            think about people first, then computers

            1 Reply Last reply Reply Quote 0
            • B Offline
              BetterAuto Pybytes Beta
              last edited by

              I also sprinkled gc.collect() all through the code, at the start and after each operation, same result.

              L 1 Reply Last reply Reply Quote 0
              • L Offline
                livius @BetterAuto
                last edited by livius

                @BetterAuto
                but i mean
                restart your device - do not run any code
                and then do above commands

                import gc
                print(gc.mem_free())
                gc.collect()
                print(gc.mem_free())
                

                and then

                import testmain3
                

                same result?
                also post here what you got with such print commands as output - how much memmory is free before import testmain3

                think about people first, then computers

                1 Reply Last reply Reply Quote 0
                • B Offline
                  BetterAuto Pybytes Beta
                  last edited by BetterAuto

                  I'm at a dead end with this. As mentioned earlier I am required to stick to only an older firmware, but that has a WLAN() bug. I detail the issue more here:
                  https://forum.pycom.io/topic/7029/anyone-using-google-cloud-not-on-pybytes?_=1620435408202

                  Thanks for attempting to help!

                  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