Skip to content

Commit b18e547

Browse files
authored
Add test from discussion
Ensures that a finally clause after a cancelled await can still use a timeout.
1 parent 5cb76e3 commit b18e547

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

Lib/test/test_asyncio/test_timeouts.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,15 @@ async def test_repr_disabled(self):
214214
async with asyncio.timeout(None) as cm:
215215
self.assertEqual(repr(cm), r"<Timeout [active] when=None>")
216216

217+
async def test_nested_timeout_in_finally(self):
218+
with self.assertRaises(TimeoutError):
219+
async with asyncio.timeout(0.01):
220+
try:
221+
await asyncio.sleep(1)
222+
finally:
223+
with self.assertRaises(TimeoutError):
224+
async with asyncio.timeout(0.01):
225+
await asyncio.sleep(10)
217226

218227

219228
@unittest.skipUnless(hasattr(tasks, '_CTask'),

0 commit comments

Comments
 (0)