-
-
Notifications
You must be signed in to change notification settings - Fork 34.5k
gh-90908: Document asyncio.Task.cancelling() and asyncio.Task.uncancel() #95253
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
708cb27
0203e01
4a6a2fe
ad49eb0
4c56381
13515f3
f0a215d
f3bcc6f
26cf287
9296af0
4114a79
50850de
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -622,13 +622,18 @@ def on_timeout(): | |
| # code might have been nested (think multiple timeouts). See | ||
| # commit 7fce1063b6e5a366f8504e039a8ccdd6944625cd for | ||
| # details. | ||
| # 5. we only convert CancelledError to TimeoutError; if the user | ||
| # code raised a different exception due to the cancellation | ||
| # (like a ConnectionLostError from a database client), we | ||
| # propagate it. | ||
| # 5. we only convert CancelledError to TimeoutError; for other | ||
| # exceptions raised due to the cancellation (like | ||
| # a ConnectionLostError from a database client), simply | ||
| # propagate them. | ||
| # | ||
| # Those checks need to take place in this exact order to make | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "Those checks" == (2), (4), (5), right? Because (1) and (3) don't describe "checks". Other than that nit, these comments seem correct, and the code looks so too (but I'm not taking money :-). (Another nit: the huge comment interrupts the logic. Maybe move it to the top of the test function?) |
||
| # sure the `cancelling()` counter always stays in sync. | ||
| # | ||
| # Additionally, the original stimulus to `cancel()` the task | ||
| # needs to be unscheduled to avoid re-cancelling the task later. | ||
| # Here we do it by cancelling `timeout_handle` in the `finally:` | ||
| # block. | ||
| raise TimeoutError | ||
| except TimeoutError: | ||
| self.assertTrue(timed_out) | ||
|
|
@@ -648,6 +653,7 @@ def on_timeout(): | |
| self.assertTrue(outer_code_reached) # task got uncancelled after leaving | ||
| # the structured block and continued until | ||
| # completion | ||
| self.assertEqual(t1.cancelling(), 0) # no pending cancellation of the outer task | ||
|
|
||
| # Test which did not time out. | ||
| t2 = self.new_task(loop, make_request_with_timeout(sleep=0, timeout=10.0)) | ||
|
|
@@ -657,6 +663,7 @@ def on_timeout(): | |
| self.assertFalse(timed_out) | ||
| self.assertTrue(structured_block_finished) | ||
| self.assertTrue(outer_code_reached) | ||
| self.assertEqual(t2.cancelling(), 0) | ||
|
|
||
| def test_cancel(self): | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that commit 7d611b4 changes the behavior again.