Skip to content

Commit 2c01807

Browse files
committed
micropython/aiorepl: Use blocking reads for raw_repl.
Signed-off-by: Andrew Leech <[email protected]>
1 parent 68e3e07 commit 2c01807

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

micropython/aiorepl/aiorepl.py

+11-6
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+
await raw_repl(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(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 = sys.stdin.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+
async def raw_repl(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 = sys.stdin.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()
288293
break
289294
else:
290295
# reset raw REPL

0 commit comments

Comments
 (0)