asyncio does not always show the full traceback

Frank Millman frank at chagford.com
Wed Mar 1 09:25:11 EST 2017


"Frank Millman"  wrote in message news:o93vs2$smi$1 at blaine.gmane.org...
>
> I use asyncio in my project, so most of my functions start with 'async' 
> and
most of my calls are preceded by 'await'.
>
> If an exception is raised, I usually get the full traceback, but sometimes 
> I
just get something like the following -
>
> Traceback (most recent call last):
>   File "C:\Users\User\aib\aib\test_data.py", line 645, in <module>
>     loop.run_until_complete(main(company))
>   File 
> "C:\Users\User\AppData\Local\Programs\Python\Python36\lib\asyncio\base_events.py", 
> line 466, in run_until_complete
>     return future.result()
> ValueError: not enough values to unpack (expected 2, got 1)
>
> It does not show the line where the ValueError occurs, and I have not 
> managed to narrow down exactly when this happens.
>

I have narrowed it down a bit.

Here is a fairly simple example, based on some code I had lying around -

import asyncio
from itertools import count

async def aenumerate(aiterable):
    counter = count()
    async for x in aiterable:
        yield next(counter), x
        await asyncio.sleep(0.5)

async def gen(n):
    for i in range(100, 100+n):
        yield i

async def aenum():
    g = gen(5)
    async for a, x in aenumerate(g):
        print(a, x)
    print('done')

async def main():
    await aenum()

loop = asyncio.get_event_loop()
loop.run_until_complete(main())

If you run this as is, it works.

I added '1/0' at various points, to force an exception.

If I put it in main() or in aenum(), I do not get the full traceback.

If I put it in aenumerate() or in gen(), I do get the traceback.

I hope this enables someone cleverer than me to figure out what is going on.

Frank




More information about the Python-list mailing list