Skip to content

Polish doc as part of asyncio doc improvement#9185

Merged
1st1 merged 5 commits intopython:masterfrom
willingc:polish-doc
Sep 13, 2018
Merged

Polish doc as part of asyncio doc improvement#9185
1st1 merged 5 commits intopython:masterfrom
willingc:polish-doc

Conversation

@willingc
Copy link
Copy Markdown
Contributor

Comment thread Doc/library/asyncio-dev.rst Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

ensure_future() is something that we need to deprioritize in the docs -- it's low-level and very confusing. asyncio.create_task() is the preferred way to spawn asyncio tasks.

Same for loop.create_task() -- it's a low-level advanced API that few need to ever use directly.

Comment thread Doc/library/asyncio-dev.rst Outdated
loop.close()

Another option is to use the :meth:`loop.run_until_complete`
(or alternatively, the provisional :meth:`asyncio.run`)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

:func:`asyncio.run`, not :meth:

Nit picking: I wouldn't focus too much on the fact that asyncio.run is provisional -- the only reason for it to be provisional is because we're unsure about some obscure edge cases. The function won't be removed and it's the preferred way of running an asyncio program (as it's almost impossible to use loop.run_until_complete API correctly :( ).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Nit picking makes clear docs ;-) Will update now.

Comment thread Doc/library/asyncio-dev.rst Outdated
task = asyncio.ensure_future(bug())
try:
loop.run_until_complete(task)
asyncio.run(task)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Just asyncio.run(bug()), the asyncio.ensure_future(bug()) is unnecessary.

loop.run_until_complete(task)
except Exception:
print("exception consumed")
asyncio.run(bug())
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I not sure but maybe keeping try/except block around asyncio.run(bug()) makes sense?
It teaches how to catch asyncio exceptions on very high level

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Well, catching exceptions around of asyncio.run() is kind of outside of the highest level of asyncio :)

@1st1 1st1 merged commit 1abba45 into python:master Sep 13, 2018
@willingc willingc deleted the polish-doc branch September 13, 2018 14:18
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 issue skip news

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants