aio-libs/async-timeout

Add an expired property

asvetlov opened this issue · 3 comments

  1. Context manager should return itself from __enter__.
  2. expired property should return True if timeout expired.

The change allows to figure out is asyncio.TimeoutError was raised by context manager itself or internal code, e.g.

try:
    async with timeout(1.0) as cm:
        await fetch()
except asyncio.TimeoutError:
    if cm.expired:
         # top level timeout
    else:
         # `fetch()` raised timeout itself

@hellysmile we discussed the change offline.
Do you agree with proposed API?

Looks perfect. Another way is just bool(cm), not sure is it clear or nor

Explicit property is better I believe.

Fixed by #16