Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changes to imported files not reflected in running code #44

Open
bitbronze opened this issue Oct 17, 2024 · 6 comments
Open

Changes to imported files not reflected in running code #44

bitbronze opened this issue Oct 17, 2024 · 6 comments

Comments

@bitbronze
Copy link

Changes to imported files are not reflected in running code

Setup

  • MicroPython board: ESP32-C6
  • MicroPython version: latest/preview
  • OS version: Windows
  • Browser: Chrome
  • Connection type: USB

To Reproduce
Steps to reproduce the behavior:

  1. Create file "importtest.py" with the following code:
    def somefunc():
    print("123")

  2. Create file "importtestrun.py" with the following code:
    import importtest
    importtest.somefunc()

  3. Run "importtestrun.py", and see that the behavior is as expected

  4. Change "importtest.py"

  5. Run "importtestrun.py", and see that the behavior is incorrect. (its still running old code)

Expected behavior
Changes in importtest.py should be reflected when importtestrun.py is run. Unfortunately this is not the case and the device needs to be disconnected and reconnected to resolve the issue and the import to work as expected with the new changes

@DeeJay
Copy link

DeeJay commented Oct 17, 2024

{Disclaimer: I am a barely competent beginner with Python/MicroPython. Not speaking on behalf of the ViperIDE team.}

Might that be the actual 'expected' behaviour? (And that your expectation is incorrect?)

With full-fat Python I think import is a 'lazy' operation that will not be repeated if the corresponding namespace already exists?

Perhaps micropython is using the same behaviour?

@ma261065
Copy link

You should just be able to do a soft reset on the device instead of dis/re-connecting.

As far as I understand it, this is by design.

@vshymanskyy
Copy link
Owner

Yes, this is how MicroPython itself works.
You need to soft-reset ant this is why you have a dedicated button in the upper right corner of the Terminal (and the Ctrl+D shortcut)

@bitbronze
Copy link
Author

Shouldn't this be handled by the IDE? Possibly soft-reset on each run (ala Thonny) or soft-reset on every file save. Because this behavior even if "expected" is pretty stupid and wastes time for people who don't expect it.

What is the underlying cause of this? Since the file is imported twice in the same interpreter session, its not reloaded?
Can someone point me to the docs that explains this behavior?
Is the reason we don't experience this in full-fat Python/Windows is that we relaunch the interpreter every time we re-run our script?

@ma261065
Copy link

ma261065 commented Oct 18, 2024

Well you can see the same behavior in just the REPL...

Put a print('Hello') at the start of importtest.py, then at a REPL prompt type import importtest a few times.

You will see that it only prints Hello once.

You have to reload the device to get it to 'un-import'.

Perhaps there could be an option in the IDE to "Auto reload on run" though? @vshymanskyy what do you think? It should probably be a toggleable setting so that the people who don't want this behaviour don't get upset.

@vshymanskyy vshymanskyy reopened this Oct 18, 2024
@vshymanskyy
Copy link
Owner

Adding an option to auto-soft-reset is easy

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants