Something I'm noticing in my application, in Uasyncio StreamReader docs, I'm expecting StreamReader.read to return as many characters up to value n.
https://github.com/peterhinch/micropyth ... UTORIAL.md
"read(n) Return as many characters as are available but no more than n."
In practice, I'm finding streamreader.read reads exactly 'n' bytes before returning form await. Maybe that's expected. Here's my snippit, I'd expect to echo each character as I'm typing, however it waits until 10 characters are queued up before returning.
Code: Select all
import sys
import gc
import uasyncio as asyncio
async def main():
sreader = asyncio.StreamReader(sys.stdin)
while True:
try:
r = await sreader.read(10)
sys.stdout.write(r)
except asyncio.CancelledError:
return
except Exception as err:
sys.print_exception(err)
return
try:
asyncio.run(main())
except KeyboardInterrupt:
pass
except Exception as err:
sys.print_exception(err)
finally:
asyncio.new_event_loop()
gc.collect()