Repository navigation
[doc] Clarify that Futures can be awaited multiple times #85447
Description
Activity
JustAnotherArchivist commented
on Jul 11, 2020 JustAnotherArchivistmannequinMannequinAuthorMore actionsWhile the situation is clear regarding coroutine objects (bpo-25887), as far as I can see, the documentation doesn't specify whether asyncio.Futures can be awaited multiple times. The code has always (at least since the integration into CPython) allowed for it since Future.__await__ simply returns Future.result() if it is already done. Is this guaranteed/intended behaviour, as also implied by some of the comments on bpo-25887, or is it considered an implementation detail?
Here are the only two things I found in the documentation regarding this:
library/asyncio-task: When a Future object is awaited it means that the coroutine will wait until the Future is resolved in some other place.
library/asyncio-future: Future is an awaitable object. Coroutines can await on Future objects until they either have a result or an exception set, or until they are cancelled.
Neither of these say anything about awaiting a Future that is already resolved, i.e. has a result, has an exception, or was cancelled.
If this is intended to be guaranteed, it should be mentioned in the Future documentation. If it is considered an implementation detail, it's probably not necessary to explicitly mention this anywhere, but it might be a good idea to add another line to e.g. the asyncio.wait example on how to correctly retrieve the result of an already-awaited Future/Task.
- addedtype-featureA feature request or enhancementA feature request or enhancement
on Jul 11, 2020 The allowance to wait for the future object multiple times is settled in stone. This cannot be changed without breaking very many codes.
So yes, asyncio guarantees that the feature is settled in stone. If set_value() / set_exception() was called, the value/exception is returned (raised) on every following
await fut.Pull request for documentation with clarification of the status quo is welcome!
- changed the title
[-]Clarify whether Futures can be awaited multiple times[/-][+][doc] Clarify that Futures can be awaited multiple times[/+]on Mar 21, 2022 - changed the title
[-]Clarify whether Futures can be awaited multiple times[/-][+][doc] Clarify that Futures can be awaited multiple times[/+]on Mar 21, 2022 I am surprised that this isn't documented. See #97738
- addeddocsDocumentation in the Doc dirDocumentation in the Doc dir3.10 (EOL)end of lifeend of life3.12only security fixesonly security fixesand removedtype-featureA feature request or enhancementA feature request or enhancement
on Oct 2, 2022 - added a commit that references this issue
on Oct 3, 2022
Metadata
Metadata
Assignees
Labels
Projects
- StatusShow more project fieldsDone
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields: