Re-import module?
Re-import module?
You've written a module. You run it, and it's not quite right. Now, is there any way to re-import it instead of rebooting the board?
Hmmm, the responses show a basic misunderstanding about the question, and for some reason I can't seem to post replies to this thread. Please note that the point of the exercise isn't to just re-import, but to re-import WITHOUT REBOOTING and pick up changes. (Ctrl-D is rebooting.)
Hmmm, the responses show a basic misunderstanding about the question, and for some reason I can't seem to post replies to this thread. Please note that the point of the exercise isn't to just re-import, but to re-import WITHOUT REBOOTING and pick up changes. (Ctrl-D is rebooting.)
Last edited by sw_dev on Thu Nov 20, 2014 8:17 pm, edited 1 time in total.
Re: Re-import module?
Currently, what I do is to Press Control-D which does a soft reset, and then re-import.
Re: Re-import module?
That's what I've been doing, but it occurs to me that python on other systems allows modules to be re-imported (Based on timestamp), so it might be available here, too.
Or, if it isn't, perhaps it should be?
Or, if it isn't, perhaps it should be?
Re: Re-import module?
(My response obviously got lost somewhere, I'll try to re-accomplish it.)
Note I said "without rebooting". The desktop python environment does this by checking file creation time to see if it needs to re-interpret the file, perhaps micropython can do something like that.
Note I said "without rebooting". The desktop python environment does this by checking file creation time to see if it needs to re-interpret the file, perhaps micropython can do something like that.
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: Re-import module?
This is a minor hassle because the REPL command history is lost. I have a workround: I hacked miniterm to send macros from a file to the Pyboard, but it's a kludge. It would be great if there were some way of retaining the REPL history. I considered doing it at the terminal end, but after some thought concluded it was a nontrivial exercise.
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.
Re: Re-import module?
(Apparently my replies are being deleted... WTF?)
There's some misunderstanding here. The idea is to NOT, repeat NOT REBOOT, and be able to re-import an edited module. The steps involved should be as follows:
1. Module X gets imported.
2. A deficiency is found with module X.
3. Module X's code is edited.
4. Through some means, module X is re-imported WITHOUT REBOOTING.
There's some misunderstanding here. The idea is to NOT, repeat NOT REBOOT, and be able to re-import an edited module. The steps involved should be as follows:
1. Module X gets imported.
2. A deficiency is found with module X.
3. Module X's code is edited.
4. Through some means, module X is re-imported WITHOUT REBOOTING.
Re: Re-import module?
sw_dev, your posts are being held for moderator approval. Why still? Dunno, maybe forum doesn't like some TLAs .
Awesome MicroPython list
Pycopy - A better MicroPython https://github.com/pfalcon/micropython
MicroPython standard library for all ports and forks - https://github.com/pfalcon/micropython-lib
More up to date docs - http://pycopy.readthedocs.io/
Pycopy - A better MicroPython https://github.com/pfalcon/micropython
MicroPython standard library for all ports and forks - https://github.com/pfalcon/micropython-lib
More up to date docs - http://pycopy.readthedocs.io/
Re: Re-import module?
sw_dev, regarding what you suggest, it's understood, and currently, it's not supported. MicroPython cannot behave in all aspects like CPython, or it won't be MicroPython any longer. Feature you ask for is rarely needed, but adds noticeable overhead to implementation - that's usually a rule for "skip this feature" we used so far. Feel free to argue for a usecase when it's unavoidably needed though. Otherwise, the suggestion is to do the same as you do with CPython - run your script from shell command line again (which for PyBoard translates to fast-reboot to start that new interpreter instance).
Awesome MicroPython list
Pycopy - A better MicroPython https://github.com/pfalcon/micropython
MicroPython standard library for all ports and forks - https://github.com/pfalcon/micropython-lib
More up to date docs - http://pycopy.readthedocs.io/
Pycopy - A better MicroPython https://github.com/pfalcon/micropython
MicroPython standard library for all ports and forks - https://github.com/pfalcon/micropython-lib
More up to date docs - http://pycopy.readthedocs.io/
Re: Re-import module?
pfalcon,
It's like adding a compile/link step to an interpreted environment. Silly, when a new command ("reimport", maybe?) could be introduced if the time/date check was considered too ponderous.
OTOH, I suppose I could just read the file from disk, and eval/exec it. (Yuck!)
Oh well...
It's like adding a compile/link step to an interpreted environment. Silly, when a new command ("reimport", maybe?) could be introduced if the time/date check was considered too ponderous.
OTOH, I suppose I could just read the file from disk, and eval/exec it. (Yuck!)
Oh well...
Re: Re-import module?
We cannot introduce arbitrary "commands" on a whim, or risk ending up as being non-Python. The closest (and Pythonic) solution along the way you suggest would be to expose sys.modules and let user .clear() it. But we have bigger (but still rare) problems with imports, e.g. https://github.com/micropython/micropython/issues/967 . So, unless someone starts pumping code for that, it'll have to wait. (But feel free to submit feature request in the tracker.)
Awesome MicroPython list
Pycopy - A better MicroPython https://github.com/pfalcon/micropython
MicroPython standard library for all ports and forks - https://github.com/pfalcon/micropython-lib
More up to date docs - http://pycopy.readthedocs.io/
Pycopy - A better MicroPython https://github.com/pfalcon/micropython
MicroPython standard library for all ports and forks - https://github.com/pfalcon/micropython-lib
More up to date docs - http://pycopy.readthedocs.io/