Skip to content

Commit

Permalink
When uncancel() reaches zero, clear _must_cancel
Browse files Browse the repository at this point in the history
This fixes the one failing test in test_timeouts.
Surprisingly, it doesn't break any other asyncio tests.
  • Loading branch information
gvanrossum committed Mar 31, 2024
1 parent 7fc5655 commit e97f22a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Lib/asyncio/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
4 changes: 4 additions & 0 deletions Modules/_asynciomodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit e97f22a

Please sign in to comment.