MemoryErrors even with frozen modules?


  • Pybytes Beta

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

  • Pybytes Beta

    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!



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


  • Pybytes Beta

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



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


  • Pybytes Beta

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



  • @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.


Log in to reply
 

Pycom on Twitter