Remove imported module from RAM
-
- Posts: 969
- Joined: Sat Feb 03, 2018 7:02 pm
Re: Remove imported module from RAM
right, that is exactly what I am doing... Successfully with smaller modules but completely unsuccessfull with this one.
In manual test it only works if i remove "some" of "some.thing" too which does not work when the code runs by itself as part of my project (where I have absolutely no references to this module as it is loaded within a function and completely deleted just as in the manual tests).
I'm sorry to bother you with this and it's fine if you don't want to look into this. But if you do, please read my messages carefully.
In manual test it only works if i remove "some" of "some.thing" too which does not work when the code runs by itself as part of my project (where I have absolutely no references to this module as it is loaded within a function and completely deleted just as in the manual tests).
I'm sorry to bother you with this and it's fine if you don't want to look into this. But if you do, please read my messages carefully.
Kevin Köck
Micropython Smarthome Firmware (with Home-Assistant integration): https://github.com/kevinkk525/pysmartnode
Micropython Smarthome Firmware (with Home-Assistant integration): https://github.com/kevinkk525/pysmartnode
Re: Remove imported module from RAM
You want to remove a subset, from RAM, of the module you've imported?kevinkk525 wrote: ↑Fri Sep 21, 2018 7:41 pmright, that is exactly what I am doing... Successfully with smaller modules but completely unsuccessfull with this one.
In manual test it only works if i remove "some" of "some.thing" too which does not work when the code runs by itself as part of my project (where I have absolutely no references to this module as it is loaded within a function and completely deleted just as in the manual tests).
I'm sorry to bother you with this and it's fine if you don't want to look into this. But if you do, please read my messages carefully.
-
- Posts: 969
- Joined: Sat Feb 03, 2018 7:02 pm
Re: Remove imported module from RAM
The module I imported
Kevin Köck
Micropython Smarthome Firmware (with Home-Assistant integration): https://github.com/kevinkk525/pysmartnode
Micropython Smarthome Firmware (with Home-Assistant integration): https://github.com/kevinkk525/pysmartnode
Re: Remove imported module from RAM
Run this and reply with output
Code: Select all
import gc
import sys
gc.collect();gc.mem_free()
from pysmartnode.networking import mqtt_receive_config
gc.collect();gc.mem_free()
del mqtt_receive_config
del sys.modules["mqtt_receive_config"]
gc.collect();gc.mem_free()
-
- Posts: 969
- Joined: Sat Feb 03, 2018 7:02 pm
Re: Remove imported module from RAM
Code: Select all
>>> import sys
>>> import gc
>>> gc.collect();gc.mem_free()
22480
>>> from pysmartnode.networking import mqtt_receive_config
>>> gc.collect();gc.mem_free()
18112
>>> del mqtt_receive_config
>>> del sys.modules["mqtt_receive_config"]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
KeyError: mqtt_receive_config
>>> del sys.modules["pysmartnode.networking.mqtt_receive_config"]
>>> gc.collect();gc.mem_free()
17936
>>> del sys.modules["pysmartnode.networking"]
>>> gc.collect();gc.mem_free()
17952
>>> del sys.modules["pysmartnode"]
>>> gc.collect();gc.mem_free()
18400
>>> sys.modules
{'uasyncio': <module 'uasyncio'>, 'uasyncio.core': <module 'uasyncio.core'>, 'main': <module 'main'>}
>>>
Kevin Köck
Micropython Smarthome Firmware (with Home-Assistant integration): https://github.com/kevinkk525/pysmartnode
Micropython Smarthome Firmware (with Home-Assistant integration): https://github.com/kevinkk525/pysmartnode
Re: Remove imported module from RAM
kevinkk525 wrote: ↑Fri Sep 21, 2018 8:04 pmCode: Select all
>>> import sys >>> import gc >>> gc.collect();gc.mem_free() 22480 >>> from pysmartnode.networking import mqtt_receive_config >>> gc.collect();gc.mem_free() 18112 >>> del mqtt_receive_config >>> del sys.modules["mqtt_receive_config"] Traceback (most recent call last): File "<stdin>", line 1, in <module> KeyError: mqtt_receive_config >>> del sys.modules["pysmartnode.networking.mqtt_receive_config"] >>> gc.collect();gc.mem_free() 17936 >>> del sys.modules["pysmartnode.networking"] >>> gc.collect();gc.mem_free() 17952 >>> del sys.modules["pysmartnode"] >>> gc.collect();gc.mem_free() 18400 >>> sys.modules {'uasyncio': <module 'uasyncio'>, 'uasyncio.core': <module 'uasyncio.core'>, 'main': <module 'main'>} >>>
Run
Code: Select all
dir()
sys.modules
import gc
import sys
gc.collect();gc.mem_free()
from pysmartnode.networking import mqtt_receive_config
dir()
sys.modules
gc.collect();gc.mem_free()
-
- Posts: 969
- Joined: Sat Feb 03, 2018 7:02 pm
Re: Remove imported module from RAM
Code: Select all
>>> dir()
['uos', 'gc', '__name__', 'main']
>>> import sys
>>> sys.modules
{'main': <module 'main'>}
>>> import gc
>>> gc.collect();gc.mem_free()
35520
>>> from pysmartnode.networking import mqtt_receive_config
>>> dir()
['uos', '__name__', 'main', 'gc', 'sys', 'mqtt_receive_config']
>>> sys.modules
{'uasyncio': <module 'uasyncio'>, 'uasyncio.core': <module 'uasyncio.core'>, 'pysmartnode.networking.mqtt_receive_config': <module 'pysmartnode.networking.mqtt_receive_config'>, 'pysmartnode.networking': <module 'pysmartnode.networking'>, 'main': <module 'main'>, 'pysmartnode': <module 'pysmartnode'>}
>>> gc.collect();gc.mem_free()
31200
Kevin Köck
Micropython Smarthome Firmware (with Home-Assistant integration): https://github.com/kevinkk525/pysmartnode
Micropython Smarthome Firmware (with Home-Assistant integration): https://github.com/kevinkk525/pysmartnode
Re: Remove imported module from RAM
I don't think you can do what you want.kevinkk525 wrote: ↑Fri Sep 21, 2018 8:10 pmCode: Select all
>>> dir() ['uos', 'gc', '__name__', 'main'] >>> import sys >>> sys.modules {'main': <module 'main'>} >>> import gc >>> gc.collect();gc.mem_free() 35520 >>> from pysmartnode.networking import mqtt_receive_config >>> dir() ['uos', '__name__', 'main', 'gc', 'sys', 'mqtt_receive_config'] >>> sys.modules {'uasyncio': <module 'uasyncio'>, 'uasyncio.core': <module 'uasyncio.core'>, 'pysmartnode.networking.mqtt_receive_config': <module 'pysmartnode.networking.mqtt_receive_config'>, 'pysmartnode.networking': <module 'pysmartnode.networking'>, 'main': <module 'main'>, 'pysmartnode': <module 'pysmartnode'>} >>> gc.collect();gc.mem_free() 31200
Functions in pysmartnode.networking could use items in pysmartnode.networking.mqtt_receive_config.
If you delete pysmartnode.networking.mqtt_receive_config, the virtual machine could crash if it tried to access things in pysmartnode.networking.mqtt_receive_config.
I'm not sure about this but it makes sense.
-
- Posts: 969
- Joined: Sat Feb 03, 2018 7:02 pm
Re: Remove imported module from RAM
even after deleting pysmartnode, pysmartnode.networking and pysmartnode.networking.mqtt_receive_config the VM worked perfectly fine in my program. (pysmartnode.networking is empty)
I opened a separete thread for this curiosity with some more explanations and observations: viewtopic.php?f=2&t=5288
I opened a separete thread for this curiosity with some more explanations and observations: viewtopic.php?f=2&t=5288
Kevin Köck
Micropython Smarthome Firmware (with Home-Assistant integration): https://github.com/kevinkk525/pysmartnode
Micropython Smarthome Firmware (with Home-Assistant integration): https://github.com/kevinkk525/pysmartnode
Re: Remove imported module from RAM
kevinkk525 wrote: ↑Fri Sep 21, 2018 8:19 pmeven after deleting pysmartnode, pysmartnode.networking and pysmartnode.networking.mqtt_receive_config the VM worked perfectly fine in my program. (pysmartnode.networking is empty)
I opened a separete thread for this curiosity with some more explanations and observations: viewtopic.php?f=2&t=5288
Not what I said
Therefore, it doesn't let you delete it.If you delete pysmartnode.networking.mqtt_receive_config, the virtual machine could crash if it tried to access things in pysmartnode.networking.mqtt_receive_config.
Does it?
Run
Code: Select all
dir(); sys.modules
del mqtt_receive_config
del sys.modules["pysmartnode.networking.mqtt_receive_config"]
dir(); sys.modules