MicroPython on ESP32 with SPIRAM support
-
- Posts: 847
- Joined: Mon Nov 20, 2017 10:18 am
Re: MicroPython on ESP32 with SPIRAM support
unfortunately that didn't work. It seems that once you import the module it puts it in memory and doesn't care if it has been deleted from the flash file system or not and it doesn't reload it when imported again.
It would be great if when you import a module that has already been imported it will remove the old one from memory and reload the new one. This will make for fast debugging of programs as I have note++ open in 1 window editing the file over ftp then I can have putty/telnet open in another window. I can jump to note++ and edit a program then jump back to putty window and press up-arrow enter to re-import the module and run it then if there is still a bug I jump back to note++ make a change then jump to putty window and press up-arrow then enter to re run the new edited program.
or something like what ampy does with serial. ampy --port /com4 run script.py
This is how I write and debug my programs with the Raspberry Pi
It would be great if when you import a module that has already been imported it will remove the old one from memory and reload the new one. This will make for fast debugging of programs as I have note++ open in 1 window editing the file over ftp then I can have putty/telnet open in another window. I can jump to note++ and edit a program then jump back to putty window and press up-arrow enter to re-import the module and run it then if there is still a bug I jump back to note++ make a change then jump to putty window and press up-arrow then enter to re run the new edited program.
or something like what ampy does with serial. ampy --port /com4 run script.py
This is how I write and debug my programs with the Raspberry Pi
-
- Posts: 847
- Joined: Mon Nov 20, 2017 10:18 am
Re: MicroPython on ESP32 with SPIRAM support
or possibly a clear memory function that will clear all variables and modules in python memory.
Re: MicroPython on ESP32 with SPIRAM support
This works:
I've created a small module test.py:
Then I've imported it:
Edit module source, change "TEST_1" to "TEST_CHANGED"
Delete the imported module:
Import again:
del module_name does not work, but del sys.modules['module_name'] does.
I've created a small module test.py:
Code: Select all
def fn(n):
print("TEST_1", n)
fn(7)
Code: Select all
>>> import sys
>>> import test
TEST_1 7
>>>
>>> test.fn(999)
TEST_1 999
>>>
Delete the imported module:
Code: Select all
>>> del sys.modules['test']
>>>
Code: Select all
>>> import test
TEST_CHANGED 7
>>>
>>> test.fn(888)
TEST_CHANGED 888
>>>
-
- Posts: 847
- Joined: Mon Nov 20, 2017 10:18 am
Re: MicroPython on ESP32 with SPIRAM support
@loboris Your a freaking genius
I just tried it and it works perfectly
I just tried it and it works perfectly
Re: MicroPython on ESP32 with SPIRAM support
What works for me is:
If you have a module, let's call it "my_module". Then you can do the following:
then you can reimport that module again.
If you have a module, let's call it "my_module". Then you can do the following:
Code: Select all
import sys
sys.modules.pop("my_module")
-
- Posts: 847
- Joined: Mon Nov 20, 2017 10:18 am
Re: MicroPython on ESP32 with SPIRAM support
It looks like note++ has a plugin called nppftp that allows you to edit remote files over ftp directly without needing filezilla.
-
- Posts: 847
- Joined: Mon Nov 20, 2017 10:18 am
Re: MicroPython on ESP32 with SPIRAM support
I have installed the nppftp plugin for note++ and connected it to the esp32 use passive binary ftp insecure and it connects fine and shows me the contents of the esp32 and I can create directories and remove directories and can delete files on the esp32 but it fails when it tries to upload or down load.
Does anyone have any idea why thus is so. I have note++ as exempt from firewall. could it because of the chunk size setting of the esp32 ftp??
edit after a little googling it could be that there maybe a problem with passive downloads in the nppftp plugin
Does anyone have any idea why thus is so. I have note++ as exempt from firewall. could it because of the chunk size setting of the esp32 ftp??
edit after a little googling it could be that there maybe a problem with passive downloads in the nppftp plugin
-
- Posts: 847
- Joined: Mon Nov 20, 2017 10:18 am
Re: MicroPython on ESP32 with SPIRAM support
@laboris
There seems to be a little bug in the telent in AP mode. I can use ftp with filezilla both in station mode over my router and in access point directly but putty will only connect to telent in station mode over my router and fails to connect in access point mode directly.
There seems to be a little bug in the telent in AP mode. I can use ftp with filezilla both in station mode over my router and in access point directly but putty will only connect to telent in station mode over my router and fails to connect in access point mode directly.
-
- Posts: 847
- Joined: Mon Nov 20, 2017 10:18 am
Re: MicroPython on ESP32 with SPIRAM support
del sys.modules['my_module'] vs sys.modules.pop("my_module")
Does del sys.modules return the memory to the heap to be able to be reallocated or does it just set it to zeros ??
I assume using sys.modules.pop will remove the module from the list and return the memory to the heap??
Does del sys.modules return the memory to the heap to be able to be reallocated or does it just set it to zeros ??
I assume using sys.modules.pop will remove the module from the list and return the memory to the heap??
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: MicroPython on ESP32 with SPIRAM support
In this post Dave Hylands suggested this piece of code, saved in boot.py, to implement reload.
Code: Select all
def reload(mod):
import sys
mod_name = mod.__name__
del sys.modules[mod_name]
return __import__(mod_name)
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.