Skip to content

tools/mpremote: Fix special handling of ctrl-D when host FS is mounted. - #8265

Closed
dpgeorge wants to merge 1 commit into
micropython:masterfrom
dpgeorge:tools-mpremote-fix-ctrl-d-mounting
Closed

dpgeorge wants to merge 1 commit into
micropython:masterfrom
dpgeorge:tools-mpremote-fix-ctrl-d-mounting

Conversation

@dpgeorge

@dpgeorge dpgeorge commented Feb 5, 2022

Copy link
Copy Markdown
Member

Changes:

  • decision to remount local filesystem on remote device is made only if "MPY: soft reboot" is seen in the output after sending a ctrl-D
  • a nice message is printed to the user when the remount occurs
  • soft reset during raw REPL is now handled correctly

Fixes issue #7731.

@dpgeorge dpgeorge added the tools Relates to tools/ directory in source, or other tooling label Feb 5, 2022
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

Merging #8265 (516cbd1) into master (203ec8c) will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #8265   +/-   ##
=======================================
  Coverage   98.47%   98.47%           
=======================================
  Files         153      153           
  Lines       20145    20145           
=======================================
  Hits        19838    19838           
  Misses        307      307           

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 203ec8c...516cbd1. Read the comment docs.

else:
if len(data_all) == 0:
if t - t_start > INITIAL_TIMEOUT:
return

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

So does this mean that every time the board is in raw mode, or any other "special" mode where no immediate response is expected, ctrl-d will essentially introduce a 0.5s delay?

Actually I guess Raw mode is exited by ctrl-d so would normally return something, such as a prompt, so should be the 0.2s timeout.

Not saying that's necessarily a problem... Just wanting to check I'm following this right.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

You are right. But it's no worse than the previous behaviour which was:

  • if nothing mounted, return immediately (that's still the behaviour here)
  • if something mounted then wait 0.5 seconds for at least one char
  • if any chars received within that 0.5 seconds then assume the ctrl-D that was sent triggered a soft reset, and then wait for all chars to be received before remounting

So the improvements here are:

  • don't ever wait longer than 5 seconds (FULL_TIMEOUT)
  • always check for "MPY: soft reboot" and a valid prompt indicator (eg ">>> ") to indicate a soft reset was done

break
time.sleep(0.05)
# Check if a soft reset occurred.
if data_all.find(b"MPY: soft reboot") == -1:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pyserial has some functions that could make this simpler, eg
read_until() reads input while watching for a desired pattern or timeout (
https://pyserial.readthedocs.io/en/latest/pyserial_api.html#serial.Serial.read_until)

Or even just using its built in timeouts rather than manually managing it here?
It's got separate settings for overall read operation timeout (https://pyserial.readthedocs.io/en/latest/pyserial_api.html#serial.Serial.timeout) and inter byte timeouts (https://pyserial.readthedocs.io/en/latest/pyserial_api.html#serial.Serial.inter_byte_timeout)

Edit:
Ah, I see there's a custom pyboard.read_until that could possibly be used, but doesn't have as fine grain timeout second. Also, the compatibility layer with telnet doesn't have the extra timeout settings, that's one reason to not use the pyserial ones.
I also haven't looked at the code in the pyserial timeouts, don't know if it's actually more efficient at all.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

We don't want to exit early if the desired pattern is found, because we still need to read and process all incoming chars until it's "quiet", to know it's ready for the remount command.

And I don't think the pyserial timeout settings are enough for the case of 3 different timeout values used here (initial wait, inter-char waits, total timeout).

@dpgeorge

dpgeorge commented Feb 7, 2022

Copy link
Copy Markdown
Member Author

Merged in fecfd52

@dpgeorge dpgeorge closed this Feb 7, 2022
@dpgeorge
dpgeorge deleted the tools-mpremote-fix-ctrl-d-mounting branch February 7, 2022 02:24
tannewt added a commit to tannewt/circuitpython that referenced this pull request Aug 12, 2023
…n-main

Translations update from Hosted Weblate
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

tools Relates to tools/ directory in source, or other tooling

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants