bpo-46771: Remove two controversial lines from Task.cancel() (GH-31623) · python/cpython@7d611b4 (original) (raw)
3 files changed
lines changed
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -205,8 +205,11 @@ def cancel(self, msg=None): | ||
205 | 205 | if self.done(): |
206 | 206 | return False |
207 | 207 | self._num_cancels_requested += 1 |
208 | -if self._num_cancels_requested > 1: | |
209 | -return False | |
208 | +# These two lines are controversial. See discussion starting at | |
209 | +# https://github.com/python/cpython/pull/31394#issuecomment-1053545331 | |
210 | +# Also remember that this is duplicated in _asynciomodule.c. | |
211 | +# if self._num_cancels_requested > 1: | |
212 | +# return False | |
210 | 213 | if self._fut_waiter is not None: |
211 | 214 | if self._fut_waiter.cancel(msg=msg): |
212 | 215 | # Leave self._fut_waiter; it may be a Task that |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -514,7 +514,11 @@ async def task(): | ||
514 | 514 | self.assertTrue(t.cancel()) |
515 | 515 | self.assertTrue(t.cancelling()) |
516 | 516 | self.assertIn(" cancelling ", repr(t)) |
517 | -self.assertFalse(t.cancel()) | |
517 | + | |
518 | +# Since we commented out two lines from Task.cancel(), | |
519 | +# this t.cancel() call now returns True. | |
520 | +# self.assertFalse(t.cancel()) | |
521 | +self.assertTrue(t.cancel()) | |
518 | 522 | |
519 | 523 | with self.assertRaises(asyncio.CancelledError): |
520 | 524 | loop.run_until_complete(t) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -2206,9 +2206,13 @@ _asyncio_Task_cancel_impl(TaskObj *self, PyObject *msg) | ||
2206 | 2206 | } |
2207 | 2207 | |
2208 | 2208 | self->task_num_cancels_requested += 1; |
2209 | -if (self->task_num_cancels_requested > 1) { | |
2210 | -Py_RETURN_FALSE; | |
2211 | - } | |
2209 | + | |
2210 | +// These three lines are controversial. See discussion starting at | |
2211 | +// https://github.com/python/cpython/pull/31394#issuecomment-1053545331 | |
2212 | +// and corresponding code in tasks.py. | |
2213 | +// if (self->task_num_cancels_requested > 1) { | |
2214 | +// Py_RETURN_FALSE; | |
2215 | +// } | |
2212 | 2216 | |
2213 | 2217 | if (self->task_fut_waiter) { |
2214 | 2218 | PyObject *res; |