import asyncio
from aiohttp import Timeout
async def main():
try:
with Timeout(1) as t1:
with Timeout(1) as t2:
await asyncio.sleep(2)
except asyncio.TimeoutError as exc:
# Which one of timers raised this `exc`?
# Something like:
# get_caller(exc) is t1 -> False
# get_caller(exc) is t2 -> True
pass
if __name__ == '__main__':
loop = asyncio.get_event_loop()
loop.run_until_complete(main())
由于两个计时器具有相同的超时时间,因此它们都可以 raise TimeoutError
。我想知道是谁做的。可能吗?