[issue40894] asyncio.gather() cancelled() always False

2021-03-20 Thread Ben Buchwald
Ben Buchwald added the comment: Hopefully I'm not too late to comment on this. I also just hit this issue, but I do not agree with the proposed PR. Only modifying _GatheringFuture.cancelled() just fixes one of the side-effects of the problem. The state of the future is still FINISHED and

[issue40894] asyncio.gather() cancelled() always False

2020-06-13 Thread Timm Wagener
Timm Wagener added the comment: Proposed changes are done and test coverage is extended. I had to change one previous test slightly *(test_one_cancellation())*, which seems in line though, with the proposed behavior. -- ___ Python tracker

[issue40894] asyncio.gather() cancelled() always False

2020-06-13 Thread Timm Wagener
Timm Wagener added the comment: Ok, seems reasonable as well. I'll change it as proposed. -- ___ Python tracker ___ ___

[issue40894] asyncio.gather() cancelled() always False

2020-06-13 Thread Kyle Stanley
Kyle Stanley added the comment: Thanks for the additional feedback, Caleb. > I think `gather()` should work the same. It would be confusing if > `future_gather.cancelled()` is false if a child is cancelled, while a plain > old outer future returns `future.cancelled() == true` if futures

[issue40894] asyncio.gather() cancelled() always False

2020-06-12 Thread Caleb Hattingh
Caleb Hattingh added the comment: Kyle is correct. By analogy with Kyle's example, the following example has no gather, only two nested futures: ``` # childfut.py import asyncio async def f(fut): await fut async def g(t): await asyncio.sleep(t) async def main(): fut_g =

[issue40894] asyncio.gather() cancelled() always False

2020-06-07 Thread Timm Wagener
Timm Wagener added the comment: TLDR; - The intention of the PR is to make a future from gather return that cancelled() is True if, and only if, cancel() has successfully been called on it (explicit user intent) and it was awaited/has finished. All other finishing is not considered

[issue40894] asyncio.gather() cancelled() always False

2020-06-07 Thread Timm Wagener
Timm Wagener added the comment: Hello Kyle, thanks for reviewing. > I'm starting to agree that it makes sense to override the behavior for > `cancelled()`. However, it might make more sense to replace the > `self._cancel_requested` check with `isinstance(self.exception(), >

[issue40894] asyncio.gather() cancelled() always False

2020-06-07 Thread Kyle Stanley
Kyle Stanley added the comment: Upon further investigation, I've realized that the issue is just that the cancel() override for `_GatheringFuture` never sets its state to CANCELLED at any point (unlike its parent), and is instead going to always be set to FINISHED because of the

[issue40894] asyncio.gather() cancelled() always False

2020-06-06 Thread Kyle Stanley
Kyle Stanley added the comment: > So, we can't rely on checking ``self.done() and self._cancel_requested`` for > future.cancelled() as this would mean that future.cancelled() would return > true for a future that fully completed if `future.cancel()` was called after > it finished (which is

[issue40894] asyncio.gather() cancelled() always False

2020-06-06 Thread Kyle Stanley
Kyle Stanley added the comment: > Specifically a future can't be cancelled once it reaches the PENDING state, > this is indicated when future.cancel() returns false; see > https://github.com/python/cpython/blob/0e96c419d7287c3c7f155c9f2de3c61020386256/Lib/asyncio/futures.py#L152 > for the

[issue40894] asyncio.gather() cancelled() always False

2020-06-06 Thread Kyle Stanley
Kyle Stanley added the comment: Thank you for the bug report Timm. While I can certainly understand the source of the confusion here, I think you may be misunderstanding an important part of cancellation for futures. Specifically a future can't be cancelled once it reaches the PENDING

[issue40894] asyncio.gather() cancelled() always False

2020-06-06 Thread Timm Wagener
Change by Timm Wagener : -- keywords: +patch pull_requests: +19898 stage: -> patch review pull_request: https://github.com/python/cpython/pull/20686 ___ Python tracker ___

[issue40894] asyncio.gather() cancelled() always False

2020-06-06 Thread Timm Wagener
New submission from Timm Wagener : It seems like the future subclass returned by asyncio.gather() (_GatheringFuture) can never return True for future.cancelled() even after it's cancel() has been invoked successfully (returning True) and an await on it actually raised a CancelledError. This