uasyncio on Pyboard?

C programming, build, interpreter/VM.
Target audience: MicroPython Developers.
Post Reply
User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

uasyncio on Pyboard?

Post by pythoncoder » Sat Dec 03, 2016 6:49 am

What is the development status of this? Currently the test programs fail. For example test_call_soon.py fails with

Code: Select all

Traceback (most recent call last):
  File "<stdin>", line 11, in <module>
AttributeError: 'module' object has no attribute 'get_event_loop'
>>> 
Pyboard V1.1 running firmware built today, with latest version of the library. The program runs on the Unix build.
Peter Hinch
Index to my micropython libraries.

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: uasyncio on Pyboard?

Post by pythoncoder » Sat Dec 03, 2016 8:28 am

A further comment on uasyncio (Unix build). In CPython AbstractEventLoop.time() returns a float representing a time in seconds relative to an arbitrary datum. MicroPython returns an integer representing a time in milliseconds. While it's a big improvement that uasyncio now has millisecond precision, this difference is a significant obstacle to writing portable code. Any comments from the devs?
Peter Hinch
Index to my micropython libraries.

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: uasyncio on Pyboard?

Post by dhylands » Sat Dec 03, 2016 10:20 pm

I guess it would be possible to create a wrapper (so not that big a barrier).

Have 2 different wrappers, one for upy and one for cpython. Decide what timebase you want to use in the rest of your program (floating point seconds or integer milliseconds) and write the wrappers accordingly.

If you happen to be on a port that doesn't have floating pointing point, then being able to use integer milliseconds would be a plus.

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Pyboard package support?

Post by pythoncoder » Sun Dec 04, 2016 8:58 am

Agreed. I can see the merits of using integers. Looking at the code it uses 30 bit integers with wrapping taken care of, so another aim is doubtless to minimise allocations. But the use of integer ms is a significant deviation from standard which impacts porting applications from CPython so should be documented.

The more general question is the development status of uasyncio on the Pyboard. If I start raising issues against it when it's not ready for release it only creates random noise on Github. The fact that its test programs fail (for the rather crucial reason of failing to instantiate an event loop) suggests it's not yet ready for use.

My interest is in assessing its usability for use in applications which access hardware. The last time I looked its timing granularity was one second rendering it unsuitable. My aim is to port some of the classes and test programs from my scheduler to uasyncio when it's ready.

The problem on the Pyboard seems to be connected with support for packages. I copied the directory trees uasyncio, uasyncio.core and uasyncio.queues from the library to the SD card. Under Unix I get

Code: Select all

>>> import uasyncio as asyncio
>>> dir(asyncio)
['StopLoop', 'EventLoop', 'start_server', 'Sleep', 'ensure_future', 'sleep', 'IOWriteDone', 'IORead', 'SysCall', 'sleep_ms', '__file__', 'IOReadDone', 'StreamWriter', 'core', 'coroutine', 'EpollEventLoop', 'type_gen', 'logging', 'SysCall1', 'heapq', 'DEBUG', '__name__', 'select', '__path__', 'uasyncio', 'StreamReader', 'IOWrite', 'log', 'get_event_loop', 'time', 'errno', 'Task', 'open_connection', '_socket']
>>> 
whereas on the Pyboard I get

Code: Select all

>>> import uasyncio as asyncio
>>> dir(asyncio)
['__name__', '__path__']
>>> 
Is there something I'm missing on installing packages on the Pyboard?
Peter Hinch
Index to my micropython libraries.

pagano.paganino
Posts: 89
Joined: Fri Sep 11, 2015 10:47 pm
Location: Italy

Re: uasyncio on Pyboard?

Post by pagano.paganino » Mon Dec 05, 2016 10:10 am

Hi pythoncoder,
i have tried your issue but it work for me.

i have fs tree on pyborad:

Code: Select all

$ ls -lah /g/lib/*
-rw-r--r-- 1 dma None 1,4K 22 ott 00.18 /g/lib/errno.py
-rw-r--r-- 1 dma None 2,0K 14 nov 12.24 /g/lib/logging.py

/g/lib/uasyncio:
totale 16K
drwxr-xr-x 1 dma None    0 14 nov 10.28 .
drwxr-xr-x 1 dma None    0 10 nov 10.44 ..
-rw-r--r-- 1 dma None 6,1K 13 nov 18.51 __init__.py
-rw-r--r-- 1 dma None 5,8K 13 nov 18.51 core.py

dma@dma-pc MSYS /c/Users/Damiano/OneDrive/micropython/uble/micropython-lib
and on the console i can see:

Code: Select all

MicroPython v1.8.6-141-g4c7d799-dirty on 2016-12-05; PYBv1.1 with STM32F405RG
Type "help()" for more information.
>>> import uasyncio as asyncio
>>> dir(asyncio)
['StopLoop', 'EventLoop', 'start_server', 'Sleep', 'ensure_future', 'sleep', 'IOWriteDone', 'IORead', 'SysCall', 'sleep_ms', '__file__', 'IOReadDone', 'StreamWriter', 'core', 'coroutine', 'EpollEventLoop', 'type_gen', 'logging', 'SysCall1', 'heapq', 'DEBUG', '__name__', 'select', '__path__', 'uasyncio', 'StreamReader', 'IOWrite', 'log', 'get_event_loop', 'time', 'errno', 'Task', 'open_connection', '_socket']
>>>
D.

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: uasyncio on Pyboard?

Post by pythoncoder » Mon Dec 05, 2016 2:19 pm

Ah! Thank you. The penny drops. From the look of your directory structure you installed it under the Unix build using upip, then copied the resultant ~/.micropython/lib tree to the pyboard. I did this and my test program worked :D

Is this how you installed it? Is the procedure documented anywhere? It seems problematic for those not running Linux. Or is there another way to run upip on the Pyboard?
Peter Hinch
Index to my micropython libraries.

pagano.paganino
Posts: 89
Joined: Fri Sep 11, 2015 10:47 pm
Location: Italy

Re: uasyncio on Pyboard?

Post by pagano.paganino » Mon Dec 05, 2016 2:51 pm

Is this how you installed it?
Yes
Is the procedure documented anywhere?
No, but can be added.
It seems problematic for those not running Linux. Or is there another way to run upip on the Pyboard?
I have done it using msys2 on Windows

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: uasyncio on Pyboard?

Post by pythoncoder » Mon Dec 05, 2016 6:02 pm

Thanks!
Peter Hinch
Index to my micropython libraries.

Post Reply