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

Commit c2a140f

Browse files
author
Vincent Michel
committed
Avoid warnings when building the docs
1 parent a1c3996 commit c2a140f

File tree

5 files changed

+77
-43
lines changed

5 files changed

+77
-43
lines changed

conf.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@
173173
# Add any paths that contain custom static files (such as style sheets) here,
174174
# relative to this directory. They are copied after the builtin static files,
175175
# so a file named "default.css" will overwrite the builtin "default.css".
176-
html_static_path = ['_static']
176+
# html_static_path = ['_static']
177177

178178
# Add any extra paths that contain custom files (such as robots.txt or
179179
# .htaccess) here, relative to this directory. These files are copied

getting_started.rst

+26-11
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@ Python 3.5 (or higher) only
88
This documentation is written for Python 3.5 to avail of the new
99
``async`` and ``await`` keywords.
1010

11-
If you have Python 3.5 installed you only need to install ``aiohttp``::
11+
If you have Python 3.5 installed you only need to install ``aiohttp``:
1212

13-
pip install -U aiohttp
13+
.. sourcecode:: console
14+
15+
$ pip install -U aiohttp
1416

1517
If you don't have Python 3.5 installed yet, you have several options
1618
to install it.
@@ -21,27 +23,37 @@ All platforms with ``conda``
2123
* Download and install
2224
`Miniconda <http://conda.pydata.org/miniconda.html>`_ for our platform.
2325
* Create a new Python 3.5 environment (named ``aio35``, use a different
24-
if you like)::
26+
if you like):
27+
28+
.. sourcecode:: console
2529

26-
conda create -n aio35 python=3.5
30+
$ conda create -n aio35 python=3.5
2731

2832
* Activate it.
29-
Linux and OS X::
33+
Linux and OS X:
34+
35+
.. sourcecode:: console
3036

3137
$ source activate aio35
3238

33-
Windows::
39+
Windows:
40+
41+
.. sourcecode:: console
3442

3543
$ source activate aio35
3644

37-
* Install ``aiohttp``::
45+
* Install ``aiohttp``:
46+
47+
.. sourcecode:: console
3848

3949
$(aio35) pip install aiohttp
4050

51+
4152
Platform specific
4253
-----------------
4354

4455
.. would be good to have some word about installing on Windows
56+
4557
* Windows: The easiest way to use Python 3.5 would be to use a package manager
4658
such as conda. See the installation instructions above.
4759
* Mac OS X: Install `Homebrew </usr/bin/ruby -e "$(curl -fsSL
@@ -55,15 +67,18 @@ Platform specific
5567
Create a virtual environment to run examples
5668
============================================
5769

58-
If you don't use conda (see above), create a virtual environment::
70+
If you don't use conda (see above), create a virtual environment:
71+
72+
.. sourcecode:: console
5973

60-
python3 -m venv venv
74+
$ python3 -m venv venv
6175

6276
.. note::
6377
Depending on your platform, the Python 3 interpreter could be invoked by
6478
``python`` instead. This is the case for conda on Windows for example.
6579

66-
Install ``aiohttp`` in the virtual environment::
80+
Install ``aiohttp`` in the virtual environment:
6781

68-
./venv/bin/python -m pip install -U aiohttp
82+
.. sourcecode:: console
6983

84+
$ ./venv/bin/python -m pip install -U aiohttp

glossary.rst

+5-4
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,11 @@ Glossary
2121

2222
future
2323
It's like a mailbox where you can subscribe to receive a result when it
24-
will be done. More details in `official documentation
25-
<https://docs.python.org/3/library/asyncio-task.html#future>`_
24+
will be done. See the `Future section`_ of the official documentation.
2625

2726
task
2827
It represents the execution of a coroutine and take care the result in a
29-
future. More details in `official documentation
30-
<https://docs.python.org/3/library/asyncio-task.html#task>`_
28+
future. See the `Task section`_ of the official documentation.
29+
30+
.. _Future section: https://docs.python.org/3/library/asyncio-task.html#future
31+
.. _Task section: https://docs.python.org/3/library/asyncio-task.html#task

hello_world.rst

+5-2
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,12 @@ all scheduled :term:`tasks <task>` could execute, which results in a warning.
4747

4848
.. literalinclude:: examples/loop_stop.py
4949

50-
Warning::
50+
Output:
5151

52+
.. sourcecode:: console
53+
54+
second hello
55+
first hello
5256
Task was destroyed but it is pending!
5357
task: <Task pending coro=<say() done, defined at examples/loop_stop.py:3>
5458
wait_for=<Future pending cb=[Task._wakeup()]>>
55-

webscraper.rst

+40-25
Original file line numberDiff line numberDiff line change
@@ -19,28 +19,40 @@ A Mock Web Server
1919

2020
This is a very simple web server. (See below for the code.)
2121
Its only purpose is to wait for a given amount of time.
22-
Test it by running it from the command line::
22+
Test it by running it from the command line:
23+
24+
.. sourcecode:: console
2325

2426
$ python simple_server.py
2527

26-
It will answer like this::
28+
It will answer like this:
29+
30+
.. sourcecode:: console
2731

2832
Serving from port 8000 ...
2933

30-
Now, open a browser and go to this URL::
34+
Now, open a browser and go to this URL:
35+
36+
.. sourcecode:: console
3137

3238
http://localhost:8000/
3339

34-
You should see this text in your browser::
40+
You should see this text in your browser:
41+
42+
.. sourcecode:: console
3543

3644
Waited for 0.00 seconds.
3745

38-
Now, add ``2.5`` to the URL::
46+
Now, add ``2.5`` to the URL:
47+
48+
.. sourcecode:: console
3949

4050
http://localhost:8000/2.5
4151

4252
After pressing enter, it will take 2.5 seconds until you see this
43-
response::
53+
response:
54+
55+
.. sourcecode:: console
4456

4557
Waited for 2.50 seconds.
4658

@@ -49,7 +61,6 @@ Use different numbers and see how long it takes until the server responds.
4961
The full implementation looks like this:
5062

5163
.. literalinclude:: examples/simple_server.py
52-
:language: python
5364

5465
Let's have a look into the details.
5566
This provides a simple multi-threaded web server:
@@ -113,11 +124,15 @@ The function ``time.perf_counter()`` provides a time stamp.
113124
Taking two time stamps a different points in time and calculating their
114125
difference provides the elapsed run time.
115126

116-
Finally, we can run our client::
127+
Finally, we can run our client:
128+
129+
.. sourcecode:: console
117130

118131
$ python synchronous_client.py
119132

120-
and get this output::
133+
and get this output:
134+
135+
.. sourcecode:: console
121136

122137
It took 11.08 seconds for a total waiting time of 11.00.
123138
Waited for 1.00 seconds.
@@ -174,9 +189,7 @@ Therefore, we need to convert our strings in to bytestrings.
174189
Next, we read header and message from the reader, which is a ``StreamReader``
175190
instance.
176191
We need to iterate over the reader by using a special or loop for
177-
``asyncio``:
178-
179-
.. code-block:: python
192+
``asyncio``::
180193

181194
async for raw_line in reader:
182195

@@ -204,14 +217,15 @@ The interesting things happen in a few lines in ``get_multiple_pages()``
204217
(the rest of this function just measures the run time and displays it):
205218

206219
.. literalinclude:: examples/async_client_blocking.py
207-
:language: python
208220
:start-after: pages = []
209221
:end-before: duration
210222

211223
We await ``get_page()`` for each page in a loop.
212224
This means, we wait until each pages has been retrieved before asking for
213225
the next.
214-
Let's run it from the command-line to see what happens::
226+
Let's run it from the command-line to see what happens:
227+
228+
.. sourcecode:: console
215229

216230
$ async_client_blocking.py
217231
It took 11.06 seconds for a total waiting time of 11.00.
@@ -249,28 +263,26 @@ The interesting part is in this loop:
249263
We append all return values of ``get_page()`` to our lits of tasks.
250264
This allows us to send out all request, in our case four, without
251265
waiting for the answers.
252-
After sending all of them, we wait for the answers, using:
266+
After sending all of them, we wait for the answers, using::
253267

254268
await asyncio.gather(*tasks)
255269

256270
The difference here is the use of ``asyncio.gather()`` that is called with all
257271
our tasks in the list ``tasks`` as arguments.
258-
The ``asyncio.gather(*tasks)`` means for our example with four list entries:
259-
260-
.. code-block:: python
272+
The ``asyncio.gather(*tasks)`` means for our example with four list entries::
261273

262274
asyncio.gather(tasks[0], tasks[1], tasks[2], tasks[3])
263275

264-
So, for a list with 100 tasks it would mean:
265-
266-
.. code-block:: python
276+
So, for a list with 100 tasks it would mean::
267277

268278
asyncio.gather(tasks[0], tasks[1], tasks[2],
269279
# 96 more tasks here
270280
tasks[99])
271281

272282

273-
Let's see if we got any faster::
283+
Let's see if we got any faster:
284+
285+
.. sourcecode:: console
274286

275287
$ async_client_nonblocking.py
276288
It took 5.08 seconds for a total waiting time of 11.00.
@@ -309,10 +321,11 @@ High-Level Approach with ``aiohttp``
309321

310322
The library aiohttp_ allows to write HTTP client and server applications,
311323
using a high-level approach.
312-
Install with::
324+
Install with:
313325

314-
$ pip install aiohttp
326+
.. sourcecode:: console
315327

328+
$ pip install aiohttp
316329

317330
.. _aiohttp: https://aiohttp.readthedocs.io/en/stable/
318331

@@ -352,7 +365,9 @@ with ``asyncio``.
352365
The only difference is the opened client session and handing over this session
353366
to ``fetch_page()`` as the first argument.
354367

355-
Finally, we run this program::
368+
Finally, we run this program:
369+
370+
.. sourcecode:: console
356371

357372
$ python aiohttp_client.py
358373
It took 5.04 seconds for a total waiting time of 11.00.

0 commit comments

Comments
 (0)