Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork33.7k
bpo-46771: Implement task cancel requests#31513
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -105,7 +105,7 @@ def __init__(self, coro, *, loop=None, name=None): | ||
| else: | ||
| self._name = str(name) | ||
| self._num_cancels_requested =0 | ||
| self._must_cancel = False | ||
| self._fut_waiter = None | ||
| self._coro = coro | ||
| @@ -198,13 +198,15 @@ def cancel(self, msg=None): | ||
| task will be marked as cancelled when the wrapped coroutine | ||
| terminates with a CancelledError exception (even if cancel() | ||
| was not called). | ||
| This also increases the task's count of cancellation requests. | ||
| """ | ||
| self._log_traceback = False | ||
| if self.done(): | ||
| return False | ||
| self._num_cancels_requested += 1 | ||
| if self._num_cancels_requested > 1: | ||
| return False | ||
| if self._fut_waiter is not None: | ||
| if self._fut_waiter.cancel(msg=msg): | ||
| # Leave self._fut_waiter; it may be a Task that | ||
| @@ -217,14 +219,24 @@ def cancel(self, msg=None): | ||
| return True | ||
| def cancelling(self): | ||
Contributor 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. Is the 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. Hm, do you have a suggestion? I was thinking that it's still usable as a "truthy" value. Usually when you're interested in the cancel count you should call Contributor 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. I have no good answer. Contributor 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. Note: 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. It's used in TaskGroup currently, so if we were to delete it we'd have to rewrite the code there in this same PR. It's also used by Contributor 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. Deal! | ||
| """Return the count of the task's cancellation requests. | ||
| This count is incremented when .cancel() is called | ||
| and may be decremented using .uncancel(). | ||
| """ | ||
| return self._num_cancels_requested | ||
| def uncancel(self): | ||
| """Decrement the task's count of cancellation requests. | ||
| This should be used by tasks that catch CancelledError | ||
| and wish to continue indefinitely until they are cancelled again. | ||
| Returns the remaining number of cancellation requests. | ||
| """ | ||
| if self._num_cancels_requested > 0: | ||
| self._num_cancels_requested -= 1 | ||
| return self._num_cancels_requested | ||
| def __step(self, exc=None): | ||
| if self.done(): | ||
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Uh oh!
There was an error while loading.Please reload this page.