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

Commit f294ef6

Browse files
committed
2 parents 59bbd61 + 6e5b44d commit f294ef6

10 files changed

+92
-11
lines changed

README.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
Asyncio documentation
22
=====================
33

4-
* Online doc: http://asyncio.readthedocs.io/
5-
* GitHub: https://github.com/haypo/asyncio-doc
4+
* Online doc: https://asyncio.readthedocs.io/
5+
* GitHub: https://github.com/asyncio-doc/asyncio-doc
66
* AsyncIO documentation is written with `Sphinx <http://www.sphinx-doc.org/>`_.
77

88

@@ -50,4 +50,4 @@ See also
5050

5151
* https://github.com/python/asyncio
5252
* http://krondo.com/an-introduction-to-asynchronous-programming-and-twisted/
53-
* http://curio.readthedocs.io/en/latest/tutorial.html
53+
* https://curio.readthedocs.io/en/latest/tutorial.html

conf.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,9 @@
104104
# The name of the Pygments (syntax highlighting) style to use.
105105
pygments_style = 'sphinx'
106106

107+
# The default language to highlight source code in.
108+
highlight_language = 'python3'
109+
107110
# A list of ignored prefixes for module index sorting.
108111
# modindex_common_prefix = []
109112

File renamed without changes.

examples/subprocess_command.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import asyncio
2+
3+
4+
async def run_command(*args):
5+
# Create subprocess
6+
process = await asyncio.create_subprocess_exec(
7+
*args,
8+
# stdout must a pipe to be accessible as process.stdout
9+
stdout=asyncio.subprocess.PIPE)
10+
# Wait for the subprocess to finish
11+
stdout, stderr = await process.communicate()
12+
# Return stdout
13+
return stdout.decode().strip()
14+
15+
16+
loop = asyncio.get_event_loop()
17+
# Gather uname and date commands
18+
commands = asyncio.gather(run_command('uname'), run_command('date'))
19+
# Run the commands
20+
uname, date = loop.run_until_complete(commands)
21+
# Print a report
22+
print('uname: {}, date: {}'.format(uname, date))
23+
loop.close()

examples/subprocess_echo.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import asyncio
2+
3+
4+
async def echo(msg):
5+
# Run an echo subprocess
6+
process = await asyncio.create_subprocess_exec(
7+
'cat',
8+
# stdin must a pipe to be accessible as process.stdin
9+
stdin=asyncio.subprocess.PIPE,
10+
# stdout must a pipe to be accessible as process.stdout
11+
stdout=asyncio.subprocess.PIPE)
12+
# Write message
13+
print('Writing {!r} ...'.format(msg))
14+
process.stdin.write(msg.encode() + b'\n')
15+
# Read reply
16+
data = await process.stdout.readline()
17+
reply = data.decode().strip()
18+
print('Received {!r}'.format(reply))
19+
# Stop the subprocess
20+
process.terminate()
21+
code = await process.wait()
22+
print('Terminated with code {}'.format(code))
23+
24+
25+
loop = asyncio.get_event_loop()
26+
loop.run_until_complete(echo('hello!'))
27+
loop.close()

http_client.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ HTTP client example:
77
.. literalinclude:: examples/http_client.py
88

99
For more information, see `aiohttp documentation
10-
<http://aiohttp.readthedocs.io/>`_.
10+
<https://aiohttp.readthedocs.io/>`_.

index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ Chapter 2: Advanced topics
2424

2525
tcp_echo.rst
2626
threads.rst
27+
subprocess.rst
2728
producer_consumer.rst
2829
debug_mode.rst
2930

@@ -66,4 +67,3 @@ Contributing
6667
:maxdepth: 2
6768

6869
README.rst
69-

producer_consumer.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Simple example
66
==============
77

88
A simple producer/consumer example, using an `asyncio.Queue
9-
<http://docs.python.org/3/library/asyncio-queue.html#asyncio.Queue>`_:
9+
<https://docs.python.org/3/library/asyncio-queue.html#asyncio.Queue>`_:
1010

1111
.. literalinclude:: examples/producer_consumer.py
1212

@@ -16,11 +16,11 @@ Using task_done()
1616

1717

1818
A simple producer/consumer example, using `Queue.task_done
19-
<http://docs.python.org/3/library/asyncio-queue.html#asyncio.Queue.task_done>`_
19+
<https://docs.python.org/3/library/asyncio-queue.html#asyncio.Queue.task_done>`_
2020
and `Queue.join
21-
<http://docs.python.org/3/library/asyncio-queue.html#asyncio.Queue.join>`_:
21+
<https://docs.python.org/3/library/asyncio-queue.html#asyncio.Queue.join>`_:
2222

23-
.. literalinclude:: examples/producer_consumer_2.py
23+
.. literalinclude:: examples/producer_consumer_join.py
2424

2525
For more information, see the `asyncio queue documentation
26-
<http://docs.python.org/3/library/asyncio-queue.html>`_.
26+
<https://docs.python.org/3/library/asyncio-queue.html>`_.

subprocess.rst

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
++++++++++
2+
Subprocess
3+
++++++++++
4+
5+
Run a subprocess and read its output
6+
====================================
7+
8+
A simple example to run commands in a subprocess using
9+
`asyncio.create_subprocess_exec
10+
<https://docs.python.org/3.6/library/asyncio-subprocess.html#asyncio.create_subprocess_exec>`_
11+
and get the output using `process.communicate
12+
<https://docs.python.org/3/library/asyncio-subprocess.html#asyncio.asyncio.subprocess.Process.communicate>`_:
13+
14+
.. literalinclude:: examples/subprocess_command.py
15+
16+
17+
Communicate with a subprocess using standard streams
18+
====================================================
19+
20+
A simple example to communicate with an echo subprocess using `process.stdin
21+
<https://docs.python.org/3/library/asyncio-subprocess.html#asyncio.asyncio.subprocess.Process.stdin>`_
22+
and `process.stdout
23+
<https://docs.python.org/3/library/asyncio-subprocess.html#asyncio.asyncio.subprocess.Process.stdout>`_:
24+
25+
.. literalinclude:: examples/subprocess_echo.py
26+
27+
For more information, see the `asyncio subprocess documentation
28+
<https://docs.python.org/3/library/asyncio-subprocess.html>`_.

webscraper.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ Install with::
362362
$ pip install aiohttp
363363

364364

365-
.. _aiohttp: http://aiohttp.readthedocs.io/en/stable/
365+
.. _aiohttp: https://aiohttp.readthedocs.io/en/stable/
366366

367367
The whole program looks like this:
368368

0 commit comments

Comments
 (0)