asyncio does not always show the full traceback

gst g.starck at gmail.com
Fri Mar 3 08:06:45 EST 2017


Le mercredi 1 mars 2017 09:25:48 UTC-5, Frank Millman a écrit :
> "Frank Millman"  wrote in message news:o93vs2$smi$1 at blaine.gmane.org...


SNIP


> 
> 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.
> 


Hi,

I ran your snippet, using 3.6 under Linux, and get the correct (imo) full traceback in all cases : 


ZeroDivisionError                         Traceback (most recent call last)
<ipython-input-4-2068e4a933e4> in <module>()
     25 
     26 loop = asyncio.get_event_loop()
---> 27 loop.run_until_complete(main())

/opt/softs/python/3.6/lib/python3.6/asyncio/base_events.py in run_until_complete(self, future)
    464             raise RuntimeError('Event loop stopped before Future completed.')
    465 
--> 466         return future.result()
    467 
    468     def stop(self):

<ipython-input-4-2068e4a933e4> in main()
     22 
     23 async def main():
---> 24     await aenum()
     25 
     26 loop = asyncio.get_event_loop()

<ipython-input-4-2068e4a933e4> in aenum()
     14 
     15 async def aenum():
---> 16     1/0
     17     g = gen(5)
     18     async for a, x in aenumerate(g):

ZeroDivisionError: division by zero

In [5]: 



BUT !

There is one time where I got a RuntimeError, and it's with 1/0 placed inside aenumerate() (after the yield) :


In [8]: 
   ...: 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) 
   ...:         1/0
   ...: 
   ...: 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()) 
   ...: 
0 100
---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
<ipython-input-8-0132c3d8fdfa> in <module>()
     25 
     26 loop = asyncio.get_event_loop()
---> 27 loop.run_until_complete(main())

/opt/softs/python/3.6/lib/python3.6/asyncio/base_events.py in run_until_complete(self, future)
    462         future.remove_done_callback(_run_until_complete_cb)
    463         if not future.done():
--> 464             raise RuntimeError('Event loop stopped before Future completed.')
    465 
    466         return future.result()

RuntimeError: Event loop stopped before Future completed.

In [9]: 


I tried reproducing it but couldn't. Other trials now always show the full traceback up to the 1/0 expression.

Not sure this helps you though..


More information about the Python-list mailing list