Dev HelpersOpen library
← Back

Catch a timeout around a task

Catch a timeout around a task in Python.

Open this example in the interactive library

Source code

import asyncio
async def main():
    try:
        async with asyncio.timeout(0):
            await asyncio.sleep(1)
    except TimeoutError:
        print('Timed out')
asyncio.run(main())

Sample output

Timed out