Skip to content

Always os.chdir("/") when reloading#9224

Merged
tannewt merged 1 commit into
adafruit:mainfrom
bill88t:chdir-always
May 13, 2024
Merged

Always os.chdir("/") when reloading#9224
tannewt merged 1 commit into
adafruit:mainfrom
bill88t:chdir-always

Conversation

@bill88t
Copy link
Copy Markdown

@bill88t bill88t commented May 4, 2024

With this PR, after every reload the current working directory will always change back to root.
With this, if the code exited while in a different directory (or autoreload was run, interrupting the code), reloading will run the code again.

Up until now, if the code had changed the working directory, CircuitPython would try to find a code.py in the working directory in the next reload.
This is exceptionally problematic for when autoreload is enabled, since the code may be interrupted without being given the chance to change back to root.
This would mean, the code would stop, and CircuitPython would find no code.py to run.

This PR just make CircuitPython always reset current working directory to root upon reload.

@deshipu
Copy link
Copy Markdown

deshipu commented May 4, 2024

I'm sure I wrote a patch for this already.

@deshipu
Copy link
Copy Markdown

deshipu commented May 4, 2024

#8296

@bill88t
Copy link
Copy Markdown
Author

bill88t commented May 4, 2024

Oh I was remembering the old behavior hadn't retested in a good bit..

Still the cwd when only using REPL isn't reset.

Adafruit CircuitPython 9.1.0-beta.1-17-g9ab8831d38 on 2024-05-02; DFRobot FireBeetle 2 ESP32-S3 with ESP32S3
>>> import os;os.getcwd();os.chdir("/Beryllium");os.getcwd()
'/'
'/Beryllium'
>>> 
soft reboot

Auto-reload is off.
Running in safe mode! Not running saved code.

You are in safe mode because:
You pressed the BOOT button at start up
Press reset to exit safe mode.

Press any key to enter the REPL. Use CTRL-D to reload.

Adafruit CircuitPython 9.1.0-beta.1-17-g9ab8831d38 on 2024-05-02; DFRobot FireBeetle 2 ESP32-S3 with ESP32S3
>>> import os;os.getcwd();os.chdir("/Beryllium");os.getcwd()
'/Beryllium'
'/Beryllium'
>>>

Meanwhile with my patch:

Adafruit CircuitPython 9.1.0-beta.1-18-g77a4e429fd on 2024-05-04; DFRobot FireBeetle 2 ESP32-S3 with ESP32S3
>>> import os;os.getcwd();os.chdir("/Beryllium");os.getcwd()
'/'
'/Beryllium'
>>> 
soft reboot

Auto-reload is off.
Running in safe mode! Not running saved code.

You are in safe mode because:
The `microcontroller` module was used to boot into safe mode.
Press reset to exit safe mode.

Press any key to enter the REPL. Use CTRL-D to reload.

Adafruit CircuitPython 9.1.0-beta.1-18-g77a4e429fd on 2024-05-04; DFRobot FireBeetle 2 ESP32-S3 with ESP32S3
>>> import os;os.getcwd();os.chdir("/Beryllium");os.getcwd()
'/'
'/Beryllium'

Copy link
Copy Markdown
Member

@tannewt tannewt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, this makes sense. Thanks!

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

Successfully merging this pull request may close these issues.

3 participants