uasyncio V3 exception detect problem.

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: 127
Joined: Sun Feb 23, 2020 3:18 pm

uasyncio V3 exception detect problem.

Post by prem111 » Tue Jun 16, 2020 6:48 am

How to correctly implement the following code for the V3 version?

V2

Code: Select all


loop = uasyncio.get_event_loop()

loop.create_task(lst_service())
loop.create_task(ble_service())
try:
    loop.run_forever()
except Exception as e:
    print("error: "+str(e))
V3

Code: Select all

async def main():
    tasks = (uart_xbee_service, uart_gps_service)
    try:

        res = await uasyncio.funcs.gather(*tasks, return_exceptions=True)

    except uasyncio.CancelledError:
        print("Cancelled.")
    except Exception as e:
        print("error")


try:
    uasyncio.run(main())
except Exception as e: # not working ?
    print("error: "+str(e))  
it works, but how detect error ?

Thanks.

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

Re: uasyncio V3 exception detect problem.

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

See my tutorial which explains this.
Peter Hinch
Index to my micropython libraries.

Post Reply