mpremote REPL and mount issues with socket:// and RFC2217 connections
Port, board and/or hardware
Any platform - affects mpremote tool when connecting via socket:// or RFC2217
MicroPython version
- mpremote 1.27.0
- Tested against MicroPython unix port 1.27.0 via
- socket://localhost:port
- rfc2217://localhost:2217
Reproduction
1 unable to mount host filesystem over socket connections
- mpremote connect socket://localhost:2218 mount .
AttributeError: 'SerialIntercept' object has no attribute 'in_waiting'
2 Incorrect newline handling in interactive repl over socket
-
Connect to MicroPython Unix port:
mpremote connect socket://localhost:2218 repl -
Type commands and observe output appears like:
>>> print("hello") hello >>>
3 repl over socket://
mpremote connect socket://localhost:2218 repl
REPL may fail to respond or hang
4 repl over rfc2217
mpremote connect rfc2217://localhost:2217 repl
Output may be delayed, laggy, or appear in bursts
pyserial's RFC2217 implementation uses a background thread to process telnet data from the socket into an internal buffer. When mpremote's REPL loop usesselect()on the socket, it signals "ready" when data arrives, butinWaiting()returns 0 because the background thread hasn't processed the data yet.
Race condition sequence:
select()returns because socket has datainWaiting()returns 0 (background thread hasn't processed yet)- REPL loop skips reading
- Next iteration:
select()returns, nowinWaiting() > 0 - Finally reads the data
This causes noticeable lag and stuttering in the REPL.
Expected behaviour
mpremote should work correctly with socket-based connections (socket://, RFC2217), providing:
- Functional mount operations
- Proper newline handling in REPL output
- Responsive REPL without lag or race conditions
Observed behaviour
- Mount operations fail with
AttributeError - REPL output has "staircase" effect (misaligned lines)
- REPL may hang or fail to get input from socket connections
- REPL output is laggy/stuttering with RFC2217 connections
Additional Information
aeb1ce6- Addin_waitingproperty to SerialIntercept class2d46d52- Fix REPL newline handling7f0abfd- Improvewaitchar()wrt socket connections1ff555c- Fix REPL race conditions with RFC2217
Code of Conduct
Yes, I agree
Unable to print unicode characters when running repl with mpremote
Port, board and/or hardware
RP2 Pico
MicroPython version
MicroPython v1.22.1 on 2024-01-05; Raspberry Pi Pico with RP2040
Reproduction
- Create a file called tt.py
- Write the following contents
print("你好")
- Run this command in the same directory:
mpremote mount . import tt
Expected behaviour
Expected to print "你好".
Observed behaviour
PS D:\PROJECTS\Github\MicroPython-uFont> mpremote mount .
Local directory . is mounted at /remote
Connected to MicroPython at COM6
Use Ctrl-] or Ctrl-x to exit this shell
>
MicroPython v1.22.1 on 2024-01-05; Raspberry Pi Pico with RP2040
Type "help()" for more information.
>>> import tt
Traceback (most recent call last):
File "<frozen runpy>", line 198, in _run_module_as_main
File "<frozen runpy>", line 88, in _run_code
File "C:\Users\YHW\AppData\Local\Programs\Python\Python312\Scripts\mpremote.exe\__main__.py", line 7, in <module>
File "C:\Users\YHW\AppData\Local\Programs\Python\Python312\Lib\site-packages\mpremote\main.py", line 536, in main
do_repl(state, argparse_repl().parse_args([]))
File "C:\Users\YHW\AppData\Local\Programs\Python\Python312\Lib\site-packages\mpremote\repl.py", line 89, in do_repl
do_repl_main_loop(
File "C:\Users\YHW\AppData\Local\Programs\Python\Python312\Lib\site-packages\mpremote\repl.py", line 54, in do_repl_main_loop
console_out_write(console_data_out)
File "C:\Users\YHW\AppData\Local\Programs\Python\Python312\Lib\site-packages\mpremote\repl.py", line 83, in console_out_write
console.write(b)
File "C:\Users\YHW\AppData\Local\Programs\Python\Python312\Lib\site-packages\mpremote\console.py", line 119, in write
buf = buf.decode() if isinstance(buf, bytes) else buf
^^^^^^^^^^^^
UnicodeDecodeError: 'utf-8' codec can't decode bytes in position 0-1: unexpected end of data
Additional Information
Obviously this error occurs on the PC, so I guess there must be something wrong with the mpremote source code. The error is also triggered when printing other unicode characters, such as Japanese, emoji, etc.
As far as I know, many people use mpremote mount . to quickly demo their code, and I'd like to, but something went wrong.
Is there any way to avoid this problem?
I could convert unicode characters to hexadecimal and print them, but that's pointless.
Printing unicode characters works perfectly fine with tools like thonny.
Code of Conduct
Yes, I agree