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-125289: Update sample code in asyncio-task.rst #125292

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

galmyk
Copy link

@galmyk galmyk commented Oct 11, 2024

gh-125289: Update sample code in asyncio-task.rst

This will change coroutines sample code in the Awaitables section and make the example clearer.


📚 Documentation preview 📚: https://cpython-previews--125292.org.readthedocs.build/

This will change **coroutines** sample code in the **Awaitables** section and make the example clearer.
Copy link

cpython-cla-bot bot commented Oct 11, 2024

All commit authors signed the Contributor License Agreement.
CLA signed

Copy link
Member

@JacobCoffee JacobCoffee left a comment

Choose a reason for hiding this comment

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

this lgtm, but more broadly: i find this example weird in general that if i as a new user copy and paste it it just throws an error.

i think it would be nice to scour the documentation and "split" examples into working/non-working and denote them as such... @willingc thoughts?

@galmyk
Copy link
Author

galmyk commented Oct 11, 2024

@JacobCoffee I agree with splitting working and not working codes. But in this case, code works, just prints a warning:

/home/gmt/a.py:10: RuntimeWarning: coroutine 'nested' was never awaited
  nested()  # will raise a "RuntimeWarning".
RuntimeWarning: Enable tracemalloc to get the object allocation traceback
42

I'm not native english speaker, So I fear my wording in the following line's comment is not correct:

ested()  # will raise a "RuntimeWarning".

It just prints the warning! If it is wrong, please propose a better comment.
Or is it better to remove that command?

@willingc
Copy link
Contributor

this lgtm, but more broadly: i find this example weird in general that if i as a new user copy and paste it it just throws an error.

i think it would be nice to scour the documentation and "split" examples into working/non-working and denote them as such... @willingc thoughts?

Hmm... there are a couple of concepts at work here: async/await, nesting coroutines, and example behavior

I think the use of main() provides a bit more confusion since it is an async function in the example to illustrate nesting. It may be better to use something other than main maybe outer().

Where print() is placed is a bit of a red herring, since it's the async/await nesting that governs behavior.

I do think it makes sense to improve this section of docs, but I want to make sure that we do it in a way that gets the point across clearly about nesting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting core review docs Documentation in the Doc dir skip news
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants