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

gh-102810 Improve the sphinx docs for asyncio.Timeout #102934

Merged

Conversation

JosephSBoyle
Copy link
Contributor

@JosephSBoyle JosephSBoyle commented Mar 22, 2023

I've drafted a PR of some updates to the sphinx docs, as requested on a prev. PR for this issue by @AlexWaygood[0].

  • Add a note recommending the use of the async context factories timeout() and timeout_at()
  • Add the missing argument to the class definition
  • Add a description of what the when param does, and it's possible values.

[0]. #102811 (comment)

- Add a note recommending the use of the async context factories timeout()
and timeout_at()
- Add the missing argument to the class definition
- Add a description of what the when param does, and it's possible values.
@AlexWaygood
Copy link
Member

AlexWaygood commented Mar 22, 2023

Thank you! FYI we get docs previews on PRs (you can access it via the "details" button on the "netlify" check down at the bottom), so there's no need to post screenshots on a docs PR :)

@JosephSBoyle
Copy link
Contributor Author

@AlexWaygood, thanks for the review - I somehow missed that repetition in my self-review.. I suppose my brain was just de-duplicating it subconsciously! (Or more likely I'm sleepy 💤)

@JosephSBoyle JosephSBoyle marked this pull request as ready for review March 22, 2023 21:52
Doc/library/asyncio-task.rst Outdated Show resolved Hide resolved
Doc/library/asyncio-task.rst Outdated Show resolved Hide resolved
Doc/library/asyncio-task.rst Outdated Show resolved Hide resolved
Co-authored-by: Alex Waygood <[email protected]>
@JosephSBoyle
Copy link
Contributor Author

On a somewhat unrelated note: it occurred to me that it's potentially confusing to have timeout and Timeout behave radically differently when used in the exact same context. timeout takes a duration and Timeout takes an expiry time, which causes
them to behave very differently.

For instance I'm sure one or more people will accidentally use one instead of the other, like so:

async with asyncio.Timeout(1):  # Most likely this `when` has already expired, since `when < loop.time()`
     await asyncio.sleep(0)     # raises a `TimeoutError`
     
async with asyncio.timeout(1):  # This is most likely what the user wants
     await asyncio.sleep(0)     # Behaves as intended

I wonder if perhaps something can be done to ameliorate this. If people agree this is problematic I can open a separate issue.

@AlexWaygood
Copy link
Member

On a somewhat unrelated note: it occurred to me that it's potentially confusing to have timeout and Timeout behave radically differently when used in the exact same context. timeout takes a duration and Timeout takes an expiry time, which causes them to behave very differently.

For instance I'm sure one or more people will accidentally use one instead of the other, like so:

async with asyncio.Timeout(1):  # Most likely this `when` has already expired, since `when < loop.time()`
     await asyncio.sleep(0)     # raises a `TimeoutError`
     
async with asyncio.timeout(1):  # This is most likely what the user wants
     await asyncio.sleep(0)     # Behaves as intended

I wonder if perhaps something can be done to ameliorate this. If people agree this is problematic I can open a separate issue.

As you say, the behaviour of timeout is likely what the user wants, and I think that's why we have examples in the docs of how to use timeout, but not Timeout, and why the docs for Timeout are only a subsection of the docs for timeout. I'm not sure what else can be done to ameliorate that :/

@gvanrossum
Copy link
Member

The Timeout class is not the recommended API. But it is just public enough that we can’t change it.

@AlexWaygood AlexWaygood changed the title gh-102810 Update the sphinx docs for asyncio.Timeout gh-102810 Improve the sphinx docs for asyncio.Timeout Mar 22, 2023
Co-authored-by: Alex Waygood <[email protected]>
Copy link
Member

@AlexWaygood AlexWaygood left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great to me, thanks @JosephSBoyle! Will wait to see if Guido has any final thoughts before merging

@AlexWaygood AlexWaygood merged commit f13fdac into python:main Mar 23, 2023
@miss-islington
Copy link
Contributor

Thanks @JosephSBoyle for the PR, and @AlexWaygood for merging it 🌮🎉.. I'm working now to backport this PR to: 3.11.
🐍🍒⛏🤖 I'm not a witch! I'm not a witch!

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Mar 23, 2023
…GH-102934)

(cherry picked from commit f13fdac)

Co-authored-by: JosephSBoyle <[email protected]>
Co-authored-by: Alex Waygood <[email protected]>
@bedevere-bot
Copy link

GH-102958 is a backport of this pull request to the 3.11 branch.

@bedevere-bot bedevere-bot removed the needs backport to 3.11 only security fixes label Mar 23, 2023
miss-islington added a commit that referenced this pull request Mar 23, 2023
(cherry picked from commit f13fdac)

Co-authored-by: JosephSBoyle <[email protected]>
Co-authored-by: Alex Waygood <[email protected]>
Fidget-Spinner pushed a commit to Fidget-Spinner/cpython that referenced this pull request Mar 27, 2023
warsaw pushed a commit to warsaw/cpython that referenced this pull request Apr 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Documentation in the Doc dir skip news topic-asyncio
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants