Skip to content

micropython/aiorepl: Use blocking reads for raw_repl. #1005

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

Merged
merged 1 commit into from
Jun 3, 2025

Conversation

andrewleech
Copy link
Contributor

raw repl mode is generally used as a command channel where all stdio traffic is related directly to the raw commands and responses sent.

For this to work in aiorepl we need to ensure background tasks don't sent/receive anything on stdio else the command channel will be corrupted.

The simplest way to achieve this is to make the raw commands blocking rather than asyncio, assuming the user wont leave the device in raw mode for too long at any one time.

@andrewleech
Copy link
Contributor Author

@dpgeorge I tested this with just raw paste in blocking, reverting the rest of raw repl to async. On an application with active log messages (~1 per second) mpremote cp commands still failed. On the same device with raw repl blocking as per this PR the file transfers work immediately.

@@ -161,7 +161,7 @@ async def task(g=None, prompt="--> "):
cmd = cmd[:-1]
sys.stdout.write("\x08 \x08")
elif c == CHAR_CTRL_A:
await raw_repl(s, g)
await raw_repl(g)
Copy link
Member

Choose a reason for hiding this comment

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

Leave s as an argument, but pass in sys.stdin.

@andrewleech andrewleech force-pushed the aiorepl_raw_blocking branch from f5ee51e to bc5bb9f Compare June 3, 2025 06:55
Raw REPL mode is generally used as a command channel where all stdio
traffic is related directly to the raw commands and responses sent.

For this to work in aiorepl we need to ensure background tasks don't sent/
receive anything on stdio else the command channel will be corrupted.

The simplest way to achieve this is to make the raw commands blocking and
atomic rather than asyncio, assuming the user wont leave the device in raw
mode for too long at any one time.

Signed-off-by: Andrew Leech <[email protected]>
@dpgeorge dpgeorge force-pushed the aiorepl_raw_blocking branch from bc5bb9f to aad2e48 Compare June 3, 2025 14:41
@dpgeorge dpgeorge merged commit aad2e48 into micropython:master Jun 3, 2025
4 checks passed
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