AssertionError in run uasyncio tasks (as_gps)

Discussion about programs, libraries and tools that work with MicroPython. Mostly these are provided by a third party.
Target audience: All users and developers of MicroPython.
Post Reply
prem111
Posts: 63
Joined: Sun Feb 23, 2020 3:18 pm

AssertionError in run uasyncio tasks (as_gps)

Post by prem111 » Sun Jun 14, 2020 6:43 pm

Hi, im have a problem in uasyncio tasks...

Code: Select all

import uasyncio as asyncio
import as_GPS
from machine import UART

uart = UART(4, 9600)
sreader = asyncio.StreamReader(uart)  # Create a StreamReader
gps = as_GPS.AS_GPS(sreader)  # Instantiate GPS

async def test():
    print('waiting for GPS data')
    await gps.data_received(position=True, altitude=True)
    for _ in range(10):
        print(gps.latitude(), gps.longitude(), gps.altitude)
        await asyncio.sleep(2)
        
loop = uasyncio.get_event_loop()
loop.create_task(test)
loop.run_forever()

Its work fine, but in cancelling and next run im have:

im give error:

Code: Select all

Traceback (most recent call last):
  File "<stdin>", line 263, in <module>
  File "/lib/uasyncio/core.py", line 109, in run_forever
  File "libs/as_GPS.py", line 192, in _run
  File "/lib/uasyncio/__init__.py", line 133, in readline
AssertionError: 
>
https://github.com/peterhinch/micropyth ... /as_GPS.py

The one solution is reboot (but I don't want it.)

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

Re: AssertionError in run uasyncio tasks (as_gps)

Post by pythoncoder » Mon Jun 15, 2020 4:30 pm

Scripts running uasyncio need some care if they are to re-run without a soft boot. This is because uasyncio stores state. This can't be resolved with the version you are using, which is for uasyncio V2: the state stored by uasyncio can only be cleared by a reboot. V3 fixes this, along with many other issues.

You should run this version of as_gps which requires uasyncio V3. Install a daily build of firmware to acquire this version. Then change your script so that it ends

Code: Select all

try:
    asyncio.run(test())
finally:
    asyncio.new_event_loop()
I can't guarantee that this will work, but it certainly fixes some known problems. I suggest you look at the V3 docs in my repo, along with the new version of the tutorial. V2 is obsolescent.
Peter Hinch

prem111
Posts: 63
Joined: Sun Feb 23, 2020 3:18 pm

Re: AssertionError in run uasyncio tasks (as_gps)

Post by prem111 » Mon Jun 15, 2020 7:29 pm

Ok, thank you, how to install uasyncio V3 without reinstalling the firmware? I have firmware with my modifications.

edit:
ok im moved extmod/uasyncio to lib/uasyncio - is V3:

Code: Select all

>>> uasyncio .__ version__
(3, 0, 0)
but:
AttributeError: 'module' object has no attribute 'StreamReader'

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

Re: AssertionError in run uasyncio tasks (as_gps)

Post by pythoncoder » Tue Jun 16, 2020 3:20 am

On my Pyboard:

Code: Select all

>>> import uasyncio
>>> uasyncio.__version__
(3, 0, 0)
>>> 'StreamReader' in dir(uasyncio)
True
Are you sure you have the latest daily build? It was missing some time ago. I raised an issue and it was fixed.
Peter Hinch

prem111
Posts: 63
Joined: Sun Feb 23, 2020 3:18 pm

Re: AssertionError in run uasyncio tasks (as_gps)

Post by prem111 » Tue Jun 16, 2020 5:05 am


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

Re: AssertionError in run uasyncio tasks (as_gps)

Post by pythoncoder » Tue Jun 16, 2020 3:43 pm

Yes, but the code is built in to the firmware if you run the latest daily build. You don't need to install it as a library. Somehow you seem to be running a version which dates back to before 1st April - see this issue.
Peter Hinch

Post Reply