uasyncio

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: uasyncio

Post by pythoncoder » Sun Apr 30, 2017 6:32 am

Integers in Python can grow without limit and MicroPython fully supports arbitrary precision in normal code. However in interrupt handlers integers must be restricted to fit in 32 bits with the two most significant bits being equal. So if it can grow to that size test its value before incrementing and take appropriate action. Or perhaps zero it after reading?

Your bug is an elementary Python error. In line 75 of the module flowMeters.py you try to read a global variable which hasn't been initialised in the module or imported. The interpreter simply can't find it to read. Consider

Code: Select all

>>> def foo():
...     global z
...     print(z)
... 
>>> foo()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<stdin>", line 3, in foo
NameError: name 'z' is not defined
>>> 
Peter Hinch
Index to my micropython libraries.

thetreerat
Posts: 15
Joined: Thu Apr 27, 2017 6:40 pm

Re: uasyncio

Post by thetreerat » Tue May 02, 2017 2:31 pm

Peter,

thanks for help with the global variable. I got that working.

I place the callback as a standalone function in my flowmeter.py file, added the flowCount to the file and now I can access the var in the class method and the callback.

Hal

thetreerat
Posts: 15
Joined: Thu Apr 27, 2017 6:40 pm

Re: uasyncio

Post by thetreerat » Tue May 23, 2017 3:08 pm

@Peter,

I saw that you mention that in 1.9 uasyncio was going to be code frozen.

Does this mean that you will no longer have to install uasyncio on a standard build?

Hal

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

Re: uasyncio

Post by pythoncoder » Tue May 23, 2017 4:41 pm

I gather it will be frozen on ESP8266. I'm not sure about other platforms.
Peter Hinch
Index to my micropython libraries.

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

Unofficial uasyncio tutorial update

Post by pythoncoder » Mon Dec 18, 2017 6:05 pm

The uasyncio unofficial tutorial and resources mentioned in the original post are now updated to match the recent improvements to uasyncio. In particular the implementation of timeouts, task cancellation and the official Lock synchronisation primitive are described.

Link https://github.com/peterhinch/micropython-async.git

The experimental modified uasyncio with support for coroutine prioritisation is also updated and uses an improved (simpler) algorithm. As per all my code, use at your own risk ;)
Peter Hinch
Index to my micropython libraries.

_jg_
Posts: 12
Joined: Sat Mar 19, 2016 3:47 am

Re: uasyncio

Post by _jg_ » Fri Feb 09, 2018 6:42 pm

hi.

is there a way to install uasync library in the SD card for quick testing?
in the github page only mentions of firmaware installation. is it necessary to install library in firmware and then burn it to the board?

regards.

EDIT: i found it already. just creating the directory and placing the py files (__init__,synchro,queues,core). this made it work.

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

uasyncio 2.0

Post by pythoncoder » Tue Feb 27, 2018 2:31 pm

I have updated this repository to reflect the release of uasyncio V2.0, which is on PyPi and supported by official firmware dated 22nd Feb 2018 or later.

uasyncio V2.0 brings no API changes unless your application runs more than 16 concurrent coroutines; in this case you need to adapt the initial call to get_event_loop() to set the queue sizes. It has substantially improved the context switching time - my benchmarks now measure ~150μs for the (best) case where a coroutine yields control with yield.

The only significant code change in my repository is to asyncio_priority.py (the variant supporting a simple priority mechanism). This has no API changes apart from get_event_loop(). It now requires uasyncio V2.0.
Peter Hinch
Index to my micropython libraries.

ltmerlin
Posts: 39
Joined: Fri Jun 28, 2019 12:34 pm

Re: uasyncio

Post by ltmerlin » Mon Jul 15, 2019 7:25 pm

Thanks for creating this fantastic uasyncio codebase! Do you have a good reference for me to start with for implementing an async websocket [u]client[/u] on the ESP32? I already looked at https://github.com/danni/uwebsockets but that is still a "blocking" socket, not using uasyncio...

I also had a look at https://github.com/jczic/MicroWebSrv but this has only a websocket [u]server[/u] implementation (a very good one, using threads). The official micropython-lib has the famous "uasyncio.websocket.server" https://github.com/micropython/micropyt ... ket.server which is used for the web REPL, but again no official asynchronous websockets client module...
Did you, as an async specialist, implemented this before or do you have any tips for an async beginner? My first instinct (faulty) was using threads, but after reading your tutorial/readme I am convinced to use async code instead of threads...

Post Reply