Skip to content
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

[doc] Clarify that Futures can be awaited multiple times #85447

Closed
JustAnotherArchivist mannequin opened this issue Jul 11, 2020 · 3 comments
Closed

[doc] Clarify that Futures can be awaited multiple times #85447

JustAnotherArchivist mannequin opened this issue Jul 11, 2020 · 3 comments
Assignees
Labels
3.10 only security fixes 3.11 only security fixes 3.12 bugs and security fixes docs Documentation in the Doc dir easy topic-asyncio

Comments

@JustAnotherArchivist
Copy link
Mannequin

JustAnotherArchivist mannequin commented Jul 11, 2020

BPO 41275
Nosy @asvetlov, @1st1, @aeros, @JustAnotherArchivist

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:

assignee = None
closed_at = None
created_at = <Date 2020-07-11.02:41:58.789>
labels = ['easy', '3.11', 'type-feature', 'expert-asyncio']
title = '[doc] Clarify that Futures can be awaited multiple times'
updated_at = <Date 2022-03-21.10:51:26.622>
user = 'https://github.com/JustAnotherArchivist'

bugs.python.org fields:

activity = <Date 2022-03-21.10:51:26.622>
actor = 'iritkatriel'
assignee = 'none'
closed = False
closed_date = None
closer = None
components = ['asyncio']
creation = <Date 2020-07-11.02:41:58.789>
creator = 'JustAnotherArchivist'
dependencies = []
files = []
hgrepos = []
issue_num = 41275
keywords = ['easy']
message_count = 2.0
messages = ['373504', '373628']
nosy_count = 4.0
nosy_names = ['asvetlov', 'yselivanov', 'aeros', 'JustAnotherArchivist']
pr_nums = []
priority = 'normal'
resolution = None
stage = None
status = 'open'
superseder = None
type = 'enhancement'
url = 'https://bugs.python.org/issue41275'
versions = ['Python 3.11']

@JustAnotherArchivist
Copy link
Mannequin Author

JustAnotherArchivist mannequin commented Jul 11, 2020

While 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.

@JustAnotherArchivist JustAnotherArchivist mannequin added topic-asyncio type-feature A feature request or enhancement labels Jul 11, 2020
@asvetlov
Copy link
Contributor

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!

@iritkatriel iritkatriel added easy 3.11 only security fixes labels Mar 21, 2022
@iritkatriel iritkatriel changed the title Clarify whether Futures can be awaited multiple times [doc] Clarify that Futures can be awaited multiple times Mar 21, 2022
@iritkatriel iritkatriel added easy 3.11 only security fixes labels Mar 21, 2022
@iritkatriel iritkatriel changed the title Clarify whether Futures can be awaited multiple times [doc] Clarify that Futures can be awaited multiple times Mar 21, 2022
@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
@ezio-melotti ezio-melotti moved this to Todo in asyncio Jul 17, 2022
@kumaraditya303 kumaraditya303 self-assigned this Oct 2, 2022
@kumaraditya303
Copy link
Contributor

I am surprised that this isn't documented. See #97738

@kumaraditya303 kumaraditya303 added docs Documentation in the Doc dir 3.10 only security fixes 3.12 bugs and security fixes and removed type-feature A feature request or enhancement labels Oct 2, 2022
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Oct 2, 2022
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Oct 2, 2022
Repository owner moved this from Todo to Done in asyncio Oct 2, 2022
miss-islington added a commit that referenced this issue Oct 2, 2022
miss-islington added a commit that referenced this issue Oct 2, 2022
carljm added a commit to carljm/cpython that referenced this issue Oct 3, 2022
* main: (2069 commits)
  pythongh-96512: Move int_max_str_digits setting to PyConfig (python#96944)
  pythongh-94808: Coverage: Check picklablability of calliter (python#95923)
  pythongh-94808: Add test coverage for PyObject_HasAttrString (python#96627)
  pythongh-94732: Fix KeyboardInterrupt race in asyncio run_forever() (python#97765)
  Fix typos in `bltinmodule.c`. (pythonGH-97766)
  pythongh-94808: `_PyLineTable_StartsLine` was not used (pythonGH-96609)
  pythongh-97681: Remove Tools/demo/ directory (python#97682)
  Fix typo in unittest docs (python#97742)
  pythongh-97728: Argument Clinic: Fix uninitialized variable in the Py_UNICODE converter (pythonGH-97729)
  pythongh-95913: Fix PEP number in PEP 678 What's New ref label (python#97739)
  pythongh-95913: Copyedit/improve New Modules What's New section (python#97721)
  pythongh-97740: Fix bang in Sphinx C domain ref target syntax (python#97741)
  pythongh-96819: multiprocessing.resource_tracker: check if length of pipe write <= 512 (python#96890)
  pythongh-97706: multiprocessing tests: Delete unused variable `rand` (python#97707)
  pythonGH-85447: Clarify docs about awaiting future multiple times (python#97738)
  [docs] Update logging cookbook with recipe for using a logger like an output… (pythonGH-97730)
  pythongh-97607: Fix content parsing in the impl-detail reST directive (python#97652)
  pythongh-95975: Move except/*/finally ref labels to more precise locations (python#95976)
  pythongh-97591: In `Exception.__setstate__()` acquire strong references before calling `tp_hash` slot (python#97700)
  pythongh-95588: Drop the safety claim from `ast.literal_eval` docs. (python#95919)
  ...
pablogsal pushed a commit that referenced this issue Oct 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.10 only security fixes 3.11 only security fixes 3.12 bugs and security fixes docs Documentation in the Doc dir easy topic-asyncio
Projects
Status: Done
Development

No branches or pull requests

4 participants