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
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
Make the case study (server) a little neater.
  • Loading branch information
cjrh committed Sep 11, 2019
commit 89f7ca26333fb80053ebf98f6ce8d8f542520be1
15 changes: 12 additions & 3 deletions Doc/library/asyncio-tutorial/case-study-chat-server.rst
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,7 @@ loop. Let's add a bit more error handling:
yield json.loads(message)
except json.decoder.JSONDecodeError:
continue
except (IncompleteReadError, ConnectionAbortedError,
ConnectionResetError, CancelledError):
except (OSError, IncompleteReadError, CancelledError):
# The connection is dead, leave.
return

Expand All @@ -241,6 +240,16 @@ deserialise properly. It seems unlikely that a client would send
through only a few invalid JSON messages, but the rest valid. For
simplicity, we'll keep what we have for now, and move onto

.. note::
There are several different kinds of connection-related errors,
like ``ConnectionError``, and ``ConnectionAbortedError`` and so on.
Unless you specifically want to know which kind of exception
occurred, it is safe to use ``OSError`` because all the connection-related
exceptions are subclasses of the built-in ``OSError``. The other
exception type to keep an eye on is ``IncompleteReadError`` which is
provided by the ``asyncio`` module, and is *not* a subclass of
``OSError``.

Sending A Message
^^^^^^^^^^^^^^^^^

Expand Down Expand Up @@ -281,7 +290,7 @@ and ``send_message()``, into their own module called ``utils.py``
(Since we'll be using these function in both our server code and
our client code!).

For completeness, here is the utils module:
For completeness, here is that final utils module:

.. literalinclude:: utils01.py
:caption: utils.py
Expand Down
0