Page 1 of 2

uasyncio - StreamReader not found ?

Posted: Fri Mar 27, 2020 12:44 pm
by prem111
after install uasyncio:

>>> upip.install('micropython-uasyncio')
Installing to: /lib/
Warning: micropython.org SSL certificate is not validated
Installing micropython-uasyncio 2.0 from https://micropython.org/pi/uasyncio/uasyncio-2.0.tar.gz
Installing micropython-uasyncio.core 2.0 from https://micropython.org/pi/uasyncio.cor ... 2.0.tar.gz

Code: Select all

uasyncio.StreamReader(uart)
AttributeError: StreamReader

Re: uasyncio - StreamReader not found ?

Posted: Fri Mar 27, 2020 2:11 pm
by kevinkk525
I suggest using the current daily build of micropython. This includes the new version of uasyncio that can also be found in the docs: https://docs.micropython.org/en/latest/ ... yncio.html
It is still young (got merged a few days ago) and might still contain some bugs, but so does the old version from pypi..

The version from pypi is now deprecated, but would still work.

Re: uasyncio - StreamReader not found ?

Posted: Sat Mar 28, 2020 10:14 am
by ltmerlin
I built the latest Micropython with the new uasyncio.
Can we still use uasyncio.StreamReader(uart) or uasyncio.StreamWriter(uart, {}) ? Or what is the right way to do this with the new Stream class?

Re: uasyncio - StreamReader not found ?

Posted: Sat Mar 28, 2020 1:49 pm
by kevinkk525
To be honest, I am not using StreamReader at the moment, so I can't comment on that. But in this thread there is a similar question: viewtopic.php?f=15&t=7925
And Peter Hinch will probably answer that, he knows more about Streams and IO than I do.

Re: uasyncio - StreamReader not found ?

Posted: Sun Mar 29, 2020 12:25 pm
by pythoncoder
[EDIT] The following is wrong. Please see later post.
StreamReader and StreamWriter do work, as does my uart example.

Code: Select all

>>> for x in sorted(dir(uasyncio)):
...     print(x)
... 
CancelledError
Event
IOQueue
Lock
Loop
Queue
Server
SingletonGenerator
Stream
StreamReader
StreamWriter
Task
TimeoutError
__class__
__file__
__name__
__path__
core
create_task
event
gather
get_event_loop
lock
open_connection
ph_delete
ph_meld
ph_pairing
run
run_until_complete
select
sleep
sleep_ms
start_server
stream_awrite
sys
ticks
ticks_add
ticks_diff
wait_for
>>> 

Re: uasyncio - StreamReader not found ?

Posted: Sun Mar 29, 2020 12:54 pm
by ltmerlin
Yes in the tagged release v1.12 StreamReader and StreamWriter are present, but I am talking about the latest Micropython commit where PR5332 (https://github.com/micropython/micropython/pull/5332) was merged. And there is no StreamReader nor StreamWriter. Is it the intention to leave it out in the future releases?

Code: Select all

MicroPython v1.12-317-g688323307-dirty on 2020-03-29; ESP32 module (spiram) with ESP32
>>>help("modules")
__main__          gc                uasyncio/lock     urandom
_boot             inisetup          uasyncio/stream   ure
_onewire          logging           ubinascii         urequests
_thread           machine           ubluetooth        uselect
_uasyncio         math              ucollections      usocket
_webrepl          micropython       ucryptolib        ussl
apa106            neopixel          uctypes           ustruct
btree             network           uerrno            utime
builtins          ntptime           uhashlib          utimeq
cmath             onewire           uhashlib          uwebsocket
dht               sys               uheapq            uzlib
ds18x20           uarray            uio               webrepl
esp               uasyncio/__init__ ujson             webrepl_setup
esp32             uasyncio/core     uos               websocket_helper
flashbdev         uasyncio/event    upip
framebuf          uasyncio/funcs    upip_utarfile
Plus any modules on the filesystem
>>>

Code: Select all

>>>import uasyncio
>>>for x in sorted(dir(uasyncio)):
>>>    print(x)
CancelledError
Event
IOQueue
Lock
Loop
SingletonGenerator
Task
TaskQueue
TimeoutError
__class__
__file__
__getattr__
__name__
__path__
__version__
_attrs
core
create_task
event
funcs
gather
get_event_loop
lock
open_connection
run
run_until_complete
select
sleep
sleep_ms
start_server
stream
sys
ticks
ticks_add
ticks_diff
wait_for

Code: Select all

>>>import uasyncio.core
>>>for x in sorted(dir(uasyncio.core)):
>>>    print(x)
CancelledError
IOQueue
Loop
SingletonGenerator
Task
TaskQueue
TimeoutError
__class__
__file__
__name__
_io_queue
_promote_to_task
_task_queue
create_task
get_event_loop
run
run_until_complete
select
sleep
sleep_ms
sys
ticks
ticks_add
ticks_diff

Code: Select all

>>>import uasyncio.event
>>>for x in sorted(dir(uasyncio.event)):
>>>    print(x)
Event
__class__
__file__
__name__
core

Code: Select all

>>>import uasyncio.funcs
>>>for x in sorted(dir(uasyncio.funcs)):
>>>    print(x)
__class__
__file__
__name__
core
gather
wait_for

Code: Select all

>>>import uasyncio.stream
>>>for x in sorted(dir(uasyncio.stream)):
>>>    print(x)
Server
Stream
__class__
__file__
__name__
core
open_connection
start_server
stream_awrite

Code: Select all

>>>import uasyncio.lock
>>>for x in sorted(dir(uasyncio.lock)):
>>>    print(x)
Lock
__class__
__file__
__name__
core

Re: uasyncio - StreamReader not found ?

Posted: Sun Mar 29, 2020 4:05 pm
by tve

Re: uasyncio - StreamReader not found ?

Posted: Mon Mar 30, 2020 4:29 am
by pythoncoder
In my earlier post I was inadvertently using an old version. StreamReader and StreamWriter are indeed missing. In my view this is unfortunate as they are present in CPython. Their loss will break code.

Re: uasyncio - StreamReader not found ?

Posted: Wed Apr 01, 2020 7:58 am
by mshahbazi
StreamReader and StreamWriter are unified into uasyncio.stream.Stream

Re: uasyncio - StreamReader not found ?

Posted: Wed Apr 01, 2020 10:14 am
by ltmerlin
Nevermind, they were added back: see https://github.com/micropython/micropython/issues/5847.