Skip to content

Commit bc5bb9f

Browse files
pi-anlandrewleech
authored andcommitted
micropython/aiorepl: Use blocking reads for raw_repl.
Signed-off-by: Andrew Leech <andrew.leech@planetinnovation.com.au>
1 parent 96bd01e commit bc5bb9f

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

micropython/aiorepl/aiorepl.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ async def task(g=None, prompt="--> "):
161161
cmd = cmd[:-1]
162162
sys.stdout.write("\x08 \x08")
163163
elif c == CHAR_CTRL_A:
164-
await raw_repl(s, g)
164+
raw_repl(sys.stdin, g)
165165
break
166166
elif c == CHAR_CTRL_B:
167167
continue
@@ -239,7 +239,7 @@ async def task(g=None, prompt="--> "):
239239
micropython.kbd_intr(3)
240240

241241

242-
async def raw_paste(s, g, window=512):
242+
def raw_paste(s, window=512):
243243
sys.stdout.write("R\x01") # supported
244244
sys.stdout.write(bytearray([window & 0xFF, window >> 8, 0x01]).decode())
245245
eof = False
@@ -248,7 +248,7 @@ async def raw_paste(s, g, window=512):
248248
file = b""
249249
while not eof:
250250
for idx in range(window):
251-
b = await s.read(1)
251+
b = s.read(1)
252252
c = ord(b)
253253
if c == CHAR_CTRL_C or c == CHAR_CTRL_D:
254254
# end of file
@@ -267,7 +267,12 @@ async def raw_paste(s, g, window=512):
267267
return file
268268

269269

270-
async def raw_repl(s: asyncio.StreamReader, g: dict):
270+
def raw_repl(s, g: dict):
271+
"""
272+
This function is blocking to prevent other
273+
async tasks from writing to the stdio stream and
274+
breaking the raw repl session.
275+
"""
271276
heading = "raw REPL; CTRL-B to exit\n"
272277
line = ""
273278
sys.stdout.write(heading)
@@ -276,15 +281,15 @@ async def raw_repl(s: asyncio.StreamReader, g: dict):
276281
line = ""
277282
sys.stdout.write(">")
278283
while True:
279-
b = await s.read(1)
284+
b = s.read(1)
280285
c = ord(b)
281286
if c == CHAR_CTRL_A:
282287
rline = line
283288
line = ""
284289

285290
if len(rline) == 2 and ord(rline[0]) == CHAR_CTRL_E:
286291
if rline[1] == "A":
287-
line = await raw_paste(s, g)
292+
line = raw_paste(s)
288293
break
289294
else:
290295
# reset raw REPL

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy