main.py:
Код: Выделить всё
import async_func_1
asyncio.run(async_func_1())
Код: Выделить всё
import async_func_2
async def async_func_1():
...
await async_func_2()
Код: Выделить всё
import heavy_function
async def async_func_2():
try:
result = await asyncio.wait_for(heavy_function(), 10)
except asyncio.TimeoutError:
print('Timeout')
Код: Выделить всё
def heavy_function():
... Some code that might take very long time
Код: Выделить всё
result = await asyncio.wait_for(heavy_function(), 10)
Код: Выделить всё
await asyncio.wait_for(asyncio.sleep(12), 10)
Подробнее здесь: https://stackoverflow.com/questions/793 ... -in-python
Мобильная версия