'asyncio whether to support tracking lines to a specific timeout

I want to trace the line where asyncio times out eg :await asyncio.sleep(100000)

import asyncio

async def eternity():
    await asyncio.sleep(1)
    print('yay!')


async def eternity2():
    await asyncio.sleep(100000)
    print('yay2!')

async def dowork():
    await eternity()
    await eternity2()
    return 1


async def main():
    try:
        await asyncio.wait_for(dowork(), timeout=2)
    except asyncio.TimeoutError: # ######## i want Traceback which line times out
        print('timeout!')
        raise

asyncio.run(main())

asyncio Whether to provide a reason to get a specific timeout and Trace to a specific line!!!!!!!!!!!!!!!!!!!!!!!!



Solution 1:[1]

Have you tried using the traceback module? For example

import traceback

try:
    int("bla")
except Exception as e:
    traceback.print_tb(e.__traceback__)

Outputs:

File "<ipython-blabla>", line 5, in <module>
    int("bla")

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 MennoK