Skip to content

Commit

Permalink
Fix #930: suppress CancelledError when Timeout raises TimeoutError (#970
Browse files Browse the repository at this point in the history
)
  • Loading branch information
asvetlov authored Jul 16, 2016
1 parent 054a0f6 commit a77d4a4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion aiohttp/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,7 @@ def __exit__(self, exc_type, exc_val, exc_tb):
if exc_type is asyncio.CancelledError and self._cancelled:
self._cancel_handler = None
self._task = None
raise asyncio.TimeoutError
raise asyncio.TimeoutError from None
if self._timeout is not None:
self._cancel_handler.cancel()
self._cancel_handler = None
Expand Down
10 changes: 10 additions & 0 deletions tests/test_timeout.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,3 +165,13 @@ def outer():
yield from task
assert task.cancelled()
assert task.done()


@pytest.mark.run_loop
def test_timeout_suppress_exception_chain(loop):

with pytest.raises(asyncio.TimeoutError) as ctx:
with Timeout(0.01, loop=loop) as t:
yield from asyncio.sleep(10, loop=loop)
assert t._loop is loop
assert ctx.value.__suppress_context__

0 comments on commit a77d4a4

Please sign in to comment.