[New-bugs-announce] [issue31131] asyncio.wait_for() TimeoutError doesn't provide full traceback

Chris Jerdonek report at bugs.python.org
Mon Aug 7 07:06:35 EDT 2017

New submission from Chris Jerdonek:

In Python 3.6.1, if asyncio.wait_for() times out with a TimeoutError, the traceback doesn't show what line the code was waiting on when the timeout occurred. This makes it more difficult to diagnose the cause of a timeout.

To reproduce, you can use the following code:

    import asyncio

    async def run():
        await asyncio.sleep(1000000)

    def main(coro):
        loop = asyncio.new_event_loop()
        future = asyncio.wait_for(coro, timeout=1)


It gives the following output (notice that the sleep() line is missing):

    $ python test-timeouterror.py 
    Traceback (most recent call last):
      File "test-timeouterror.py", line 12, in <module>
      File "test-timeouterror.py", line 10, in main
      File "/Users/.../python3.6/asyncio/base_events.py", line 466,
         in run_until_complete
        return future.result()
      File "/Users/.../python3.6/asyncio/tasks.py", line 356, in wait_for
        raise futures.TimeoutError()

It seems like it should be possible to show the full traceback because, for example, if I register a signal handler with loop.add_signal_handler() as described here:
and press Control-C before the timeout occurs, I do get a full traceback showing the line:

    await asyncio.sleep(1000000)

components: Library (Lib), asyncio
messages: 299845
nosy: chris.jerdonek, yselivanov
priority: normal
severity: normal
status: open
title: asyncio.wait_for() TimeoutError doesn't provide full traceback
type: behavior
versions: Python 3.6

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list