8000 bpo-34831: Asyncio tutorial by cjrh · Pull Request #9748 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

bpo-34831: Asyncio tutorial #9748

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

Closed
wants to merge 31 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
16d3b94
Create basic structure of the asyncio tutorial
cjrh Oct 7, 2018
50a901e
Begun work on the case study for the server
cjrh Oct 14, 2018
dfede40
Incorporate review comments from @willingc
cjrh Oct 21, 2018
a11e659
Refine language around threads and processes
cjrh Oct 21, 2018
7e205d2
Incorporate message handling into server code
cjrh Oct 21, 2018
7f2f149
Add message receiving to server code.
cjrh Oct 21, 2018
61402e1
Added skeleton suggestions for the cookbook section
cjrh Oct 21, 2018
550bdbf
Further notes in the cookbook
cjrh Oct 21, 2018
e7bc56d
Further work on describing how async def functions work
cjrh Nov 4, 2018
3d4cdae
Fix review comment from @tirkarthi
cjrh Jun 15, 2019
e0bb48b
Fix typo
cjrh Jun 15, 2019
5e4550a
Clarify the "What is async" section
cjrh Jun 15, 2019
0de2748
Flesh out the sync-versus-async functions section
cjrh Jun 15, 2019
89364f8
Add the blurb entry
cjrh Jun 15, 2019
be474f4
Remove TODOs
cjrh Jun 15, 2019
c403101
Write "Executing Async Functions"
cjrh Jun 15, 2019
69190b8
Fix spurious backtick
cjrh Jun 15, 2019
89f7ca2
Make the case study (server) a little neater.
cjrh Jun 15, 2019
36fc743
Some refactoring and finishing off the server.
cjrh Jun 15, 2019
d55d8fb
Cleaned up the last bit of the chat server code sample.
cjrh Jun 16, 2019
34306f0
Further progress - got a CLI chat client working using prompt-toolkit.
cjrh Jun 16, 2019
0c82755
Include chat client code in the text.
cjrh Jun 16, 2019
a774a98
Fix typo
cjrh Jun 17, 2019
eedbc97
Clarify switching behaviour
cjrh Jun 17, 2019
a8a801d
Add async generators and async context managers discussion.
cjrh Jun 17, 2019
8e6dcfd
Add some comparison with JavaScript async/await and asyncio.create_task
cjrh Jun 17, 2019
0e5ed3f
Fix "no good read" typo
cjrh Jun 17, 2019
4714ed2
Fix "do not required" typo
cjrh Jun 17, 2019
d71da67
Modern -> modern
cjrh Jun 17, 2019
26cc634
Removing the GUI case study section
cjrh Jun 19, 2019
9530021
Remove problematic backticks inside a code-block
cjrh Sep 11, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Incorporate review comments from @willingc
  • Loading branch information
cjrh committed Sep 11, 2019
commit dfede40791ad404ae7e7178771bdc515bfe334d1
10 changes: 7 additions & 3 deletions Doc/library/asyncio-tutorial/async-functions.rst
10000
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ and look like this:
def f(x, y):
print(x + y)

# Evaluate the function
f(1, 2)

The snippet also shows how the function is evaluated. Async functions are
different in two respects:
Async functions are different in two respects:

.. code-block:: python

Expand All @@ -21,13 +21,17 @@ different in two respects:
async def f(x, y):
print(x + y)

# Execute the *async* function above
asyncio.run(f(1, 2))

The first difference is that the function declaration is spelled
``async def``. The second difference is that async functions cannot be
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
``async def``. The second difference is that async functions cannot be
:keyword:`async def`. The second difference is that async functions cannot be

executed by simply evaluating them. Here, we use the ``run()`` function
executed by simply evaluating them. Instead, we use the ``run()`` function
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
executed by simply evaluating them. Instead, we use the ``run()`` function
executed by simply evaluating them. Instead, we use the :func:`~asyncio.run` function

from the ``asyncio`` module.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
from the ``asyncio`` module.
from the :mod:`asyncio` module.


Executing Async Functions
-------------------------

The ``run`` function is only good for executing an async function
from "synchronous" code; and this is usually only used to execute
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
from "synchronous" code; and this is usually only used to execute
from *synchronous* code; and this is usually only used to execute

a "main" async function, from which others can be called in a simpler
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
a "main" async function, from which others can be called in a simpler
a *main* async function, from which others can be called in a simpler

Expand Down
2 changes: 1 addition & 1 deletion Doc/library/asyncio-tutorial/index.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Asyncio Tutorial
================

Programming with ``async def`` functions is different to normal Python
Programming with ``async def`` functions is differs from normal Python
functions; enough so that it is useful to explain a bit more
about what ``asyncio`` is for, and how to use it in typical
programs.
Expand Down
0