Page 1 of 1

uasyncio V3 exception detect problem.

Posted: Tue Jun 16, 2020 6:48 am
by prem111
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.

Re: uasyncio V3 exception detect problem.

Posted: Tue Jun 16, 2020 3:38 pm
by pythoncoder
See my tutorial which explains this.