Skip to content
This repository was archived by the owner on May 31, 2021. It is now read-only.

Reformatted files to 80 characters per line #5

Merged
merged 1 commit into from
Jul 24, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 2 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ Ideas
* Advanced section:

- protocols and transports: as least point to good implementations
- explain how to *test* asyncio applications. `Twisted documentation example <https://twistedmatrix.com/documents/current/core/howto/trial.html>`_
- explain how to *test* asyncio applications. `Twisted documentation example
<https://twistedmatrix.com/documents/current/core/howto/trial.html>`_

How to install Sphinx
=====================
Expand Down
25 changes: 21 additions & 4 deletions conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#
# import os
# import sys
# sys.path.insert(0, os.path.abspath('.'))
import os
import sys
sys.path.insert(0, os.path.abspath('.'))

# -- General configuration ------------------------------------------------

Expand All @@ -29,7 +29,7 @@
# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = []
#extensions = ['alabaster']

# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
Expand Down Expand Up @@ -119,8 +119,25 @@
# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
import alabaster
html_theme = 'alabaster'

html_theme_path = [alabaster.get_path()]
extensions = ['alabaster', 'sphinx.ext.intersphinx']
html_theme = 'alabaster'
html_sidebars = {
'**': [
'about.html',
'navigation.html',
'relations.html',
'searchbox.html',
'donate.html',
'localtoc.html',
'sourcelink.html',
]
}
intersphinx_mapping = {'python': ('https://docs.python.org/3.5', None)}

# Theme options are theme-specific and customize the look and feel of a theme
# further. For a list of options available for each theme, see the
# documentation.
Expand Down
15 changes: 10 additions & 5 deletions getting_started.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,21 @@ Getting Started
Get Python 3.5
==============

Sorry but this documentation is written for Python 3.5 to avail of the new ``async``
Sorry but this documentation is written for Python 3.5 to avail of the new
``async``
and ``await`` keywords.

.. would be good to have some word about installing on Windows
* Windows: the easiest way to use Python 3.5 would be to use a package manager like Conda
There are instructions for using a python 3.5 environment in `Conda here <http://conda.pydata.org/docs/py2or3.html#create-a-python-3-5-environment>`_.
* Windows: the easiest way to use Python 3.5 would be to use a package manager
like Conda
There are instructions for using a python 3.5 environment in `Conda here
<http://conda.pydata.org/docs/py2or3.html#create-a-python-3-5-environment>`_.
* Mac OS X: install `Homebrew </usr/bin/ruby -e "$(curl -fsSL
https://raw.githubusercontent.com/Homebrew/install/master/install)">`_ and
then type ``brew install python3``
* Linux: Ubuntu 16.04+ and Arch linux ship with Python 3.5 included.
If you don't have Python 3.5+ on your computer, you can compile it or use `Pythonz <https://github.com/saghul/pythonz>`_
If you don't have Python 3.5+ on your computer, you can compile it or use
`Pythonz <https://github.com/saghul/pythonz>`_


Create a virtual environment to run examples
Expand All @@ -26,7 +30,8 @@ Create a virtual environment::
python3 -m venv venv

.. note::
Depending on your platform, the python 3 interpreter could be invoked by ``python`` instead. This is the case for Conda on Windows for example.
Depending on your platform, the python 3 interpreter could be invoked by
``python`` instead. This is the case for Conda on Windows for example.

Install aiohttp in the virtual environment::

Expand Down
17 changes: 13 additions & 4 deletions glossary.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,22 @@ Glossary
.. glossary::

coroutine
A coroutine is a piece of code that can be paused and resumed. In contrast to threads which are preemptively multitasked by the operating system, coroutines multitask cooperatively. I.e. they choose when to pause (or to use terminology for coroutines before 3.4 - ``yield``) execution. They can also execute other coroutines.
A coroutine is a piece of code that can be paused and resumed. In
contrast to threads which are preemptively multitasked by the operating
system, coroutines multitask cooperatively. I.e. they choose when to
pause (or to use terminology for coroutines before 3.4 - ``yield``)
execution. They can also execute other coroutines.

event loop
The event loop is the central execution device to launch execution of coroutines and handle I/O (Network, sub-processes...)
The event loop is the central execution device to launch execution of
coroutines and handle I/O (Network, sub-processes...)

future
It's like a mailbox where you can subscribe to receive a result when it will be done. More details in `official documentation <https://docs.python.org/3/library/asyncio-task.html#future>`_
It's like a mailbox where you can subscribe to receive a result when it
will be done. More details in `official documentation
<https://docs.python.org/3/library/asyncio-task.html#future>`_

task
It represents the execution of a coroutine and take care the result in a future. More details in `official documentation <https://docs.python.org/3/library/asyncio-task.html#task>`_
It represents the execution of a coroutine and take care the result in a
future. More details in `official documentation
<https://docs.python.org/3/library/asyncio-task.html#task>`_
10 changes: 6 additions & 4 deletions hello_clock.rst
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
Hello Clock
^^^^^^^^^^^

Example illustrating how to schedule two :term:`coroutines <coroutine>` to run concurrently.
They run for ten minutes, during which the first :term:`coroutine <coroutine>` is scheduled every
second, while the second is scheduled every minute.
Example illustrating how to schedule two :term:`coroutines <coroutine>` to run
concurrently. They run for ten minutes, during which the first :term:`coroutine
<coroutine>` is scheduled to run every second, while the second is scheduled to
run every minute.

The function `asyncio.gather` is used to schedule both :term:`coroutines <coroutine>` at once.
The function `asyncio.gather` is used to schedule both :term:`coroutines
<coroutine>` at once.

.. literalinclude:: examples/hello_clock.py
24 changes: 16 additions & 8 deletions hello_world.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,19 @@
Hello World
+++++++++++

This is a series of examples showing the basics of how write :term:`coroutines <coroutine>` and
This is a series of examples showing the basics of how write :term:`coroutines
<coroutine>` and
schedule them in the asyncio :term:`event loop <event loop>`.

Simple coroutine
----------------

Example using the :meth:`BaseEventLoop.run_until_complete` method to schedule a
Example using the :py:meth:`asyncio.BaseEventLoop.run_until_complete` method to
schedule a
simple function that will wait one second, print 'hello' and then finish.

Because it is launched with `run_until_complete`, the :term:`event loop <event loop>` itself
Because it is launched with `run_until_complete`, the :term:`event loop <event
loop>` itself
will terminate once the :term:`coroutine <coroutine>` is completed.

.. literalinclude:: examples/hello_world.py
Expand All @@ -20,13 +23,16 @@ will terminate once the :term:`coroutine <coroutine>` is completed.
Creating tasks
--------------

This second example show how you can schedule multiple :term:`coroutines <coroutine>` in the
This second example show how you can schedule multiple :term:`coroutines
<coroutine>` in the
event loop, and then run the :term:`event loop <event loop>`.

Notice that this example will print 'second_hello' before 'first_hello',
as the first :term:`task <task>` scheduled waits longer that the second one before printing.
as the first :term:`task <task>` scheduled waits longer that the second one
before printing.

Also note that this example will never terminate, as the :term:`loop <event loop>` is asked to
Also note that this example will never terminate, as the :term:`loop <event
loop>` is asked to
`run_forever`.

.. literalinclude:: examples/create_task.py
Expand All @@ -35,13 +41,15 @@ Also note that this example will never terminate, as the :term:`loop <event loo
Stopping the loop
-----------------

This third example adds another :term:`task <task>` that will stop the :term:`event loop <event loop>` before
This third example adds another :term:`task <task>` that will stop the
:term:`event loop <event loop>` before
all scheduled :term:`tasks <task>` could execute, which results in a warning.

.. literalinclude:: examples/loop_stop.py

Warning::

Task was destroyed but it is pending!
task: <Task pending coro=<say() done, defined at examples/loop_stop.py:3> wait_for=<Future pending cb=[Task._wakeup()]>>
task: <Task pending coro=<say() done, defined at examples/loop_stop.py:3>
wait_for=<Future pending cb=[Task._wakeup()]>>

8 changes: 8 additions & 0 deletions index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,11 @@ See also
* `Writing Redis in Python with asyncio: Part 1
<http://jamesls.com/writing-redis-in-python-with-asyncio-part-1.html>`_
by James Saryerwinnie

Contributing
============

.. toctree::
:maxdepth: 2

README.rst