From e97f22aa0d28790828b363d765b2db5027671d90 Mon Sep 17 00:00:00 2001 From: Guido van Rossum Date: Sun, 31 Mar 2024 13:39:07 -0700 Subject: [PATCH] When uncancel() reaches zero, clear _must_cancel This fixes the one failing test in test_timeouts. Surprisingly, it doesn't break any other asyncio tests. --- Lib/asyncio/tasks.py | 2 ++ Modules/_asynciomodule.c | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/Lib/asyncio/tasks.py b/Lib/asyncio/tasks.py index 48e31af9a431676..076a087b7c5f002 100644 --- a/Lib/asyncio/tasks.py +++ b/Lib/asyncio/tasks.py @@ -254,6 +254,8 @@ def uncancel(self): """ if self._num_cancels_requested > 0: self._num_cancels_requested -= 1 + if self._num_cancels_requested == 0: + self._must_cancel = False # EXPERIMENTAL return self._num_cancels_requested def __eager_start(self): diff --git a/Modules/_asynciomodule.c b/Modules/_asynciomodule.c index 29246cfa6afd00c..59d422dbb72456d 100644 --- a/Modules/_asynciomodule.c +++ b/Modules/_asynciomodule.c @@ -2393,6 +2393,10 @@ _asyncio_Task_uncancel_impl(TaskObj *self) { if (self->task_num_cancels_requested > 0) { self->task_num_cancels_requested -= 1; + if (self->task_num_cancels_requested == 0) { + self->task_must_cancel = 0; + Py_CLEAR(self->task_cancel_msg); + } } return PyLong_FromLong(self->task_num_cancels_requested); }