diff --git a/trio/_sync.py b/trio/_sync.py index 8b454109b2..f05d77829f 100644 --- a/trio/_sync.py +++ b/trio/_sync.py @@ -968,7 +968,10 @@ def abort_fn(_): return _core.Abort.SUCCEEDED self._get_wait[task] = None - value = await _core.wait_task_rescheduled(abort_fn) + try: + value = await _core.wait_task_rescheduled(abort_fn) + finally: + self._get_wait.pop(task, None) return value @aiter_compat diff --git a/trio/tests/test_sync.py b/trio/tests/test_sync.py index 2e28471ecc..cd0a166bf6 100644 --- a/trio/tests/test_sync.py +++ b/trio/tests/test_sync.py @@ -5,6 +5,7 @@ from ..testing import wait_all_tasks_blocked, assert_checkpoints from .. import _core +from .. import _timeouts from .._timeouts import sleep_forever from .._sync import * @@ -407,6 +408,11 @@ async def test_Queue(): q.get_nowait() assert q.empty() + with _timeouts.move_on_after(0.01) as timeout_scope: + await q.get() + assert timeout_scope.cancelled_caught + await q.put("Test for https://github.com/python-trio/trio/pull/553") + async def test_Queue_iter(): q = Queue(1)