diff --git a/docs/customization.py b/docs/customization.py index d9feb20..27d69d1 100644 --- a/docs/customization.py +++ b/docs/customization.py @@ -1,7 +1,12 @@ # Adapted from https://hg.python.org/cpython/file/default/Doc/tools/extensions/pyspecific.py . -from sphinx import addnodes -from sphinx.domains.python import PyModulelevel, PyClassmember +from sphinx import addnodes, __version__ + +if tuple(map(int,__version__.split('.'))) >= (4, 0, 0): + from sphinx.domains.python import PyAttribute, PyFunction +else: + from sphinx.domains.python import PyModulelevel, PyClassmember + PyFunction, PyAttribute = PyModulelevel, PyClassmember class PyCoroutineMixin(object): @@ -12,18 +17,18 @@ def handle_signature(self, sig, signode): return ret -class PyAsyncFunction(PyCoroutineMixin, PyModulelevel): +class PyAsyncFunction(PyCoroutineMixin, PyFunction): def run(self): self.name = 'py:function' - return PyModulelevel.run(self) + return PyFunction.run(self) -class PyAsyncMethod(PyCoroutineMixin, PyClassmember): +class PyAsyncMethod(PyCoroutineMixin, PyAttribute): def run(self): self.name = 'py:method' - return PyClassmember.run(self) + return PyAttribute.run(self) def setup(app): diff --git a/docs/reference.rst b/docs/reference.rst index fbb50b2..33963c0 100644 --- a/docs/reference.rst +++ b/docs/reference.rst @@ -1390,6 +1390,7 @@ The following functions are also available. They accept the same arguments as t equivalents in the :mod:`subprocess` module: .. asyncfunction:: run(args, stdin=None, input=None, stdout=None, stderr=None, shell=False, check=False) + :noindex: Run a command in a subprocess. Returns a :class:`subprocess.CompletedProcess` instance. If cancelled, the underlying process is terminated using the process ``kill()`` method. diff --git a/docs/tutorial.rst b/docs/tutorial.rst index 2f37e13..439c751 100644 --- a/docs/tutorial.rst +++ b/docs/tutorial.rst @@ -64,7 +64,9 @@ This program does two things at once:: curio.run(parent) ``curio.spawn()`` launches a concurrent task. The ``join()`` method waits -for it to finish and returns its result. The following output is produced:: +for it to finish and returns its result. The following output is produced: + +.. code-block:: console bash % python3 hello.py Getting around to doing my homework @@ -141,7 +143,9 @@ Likewise, cancellation can be caught. For example:: print("No go diggy die!") raise -Now the program produces this output:: +Now the program produces this output: + +.. code-block:: console bash % python3 hello.py Getting around to doing my homework @@ -153,7 +157,7 @@ Now the program produces this output:: Are you done yet? We've got to go! No go diggy die! - bash % + bash % This is the basic gist of tasks. You can create tasks, join tasks, and cancel tasks. @@ -190,7 +194,9 @@ Running this code, you will either get output similar to this:: T-minus 7 Result: 1554 -or you will get this if the ``kid()`` took too long:: +or you will get this if the ``kid()`` took too long: + +.. code-block:: console Getting around to doing my homework T-minus 10 @@ -305,7 +311,9 @@ An Echo Server -------------- A common use of Curio is network programming. Here is an -echo server:: +echo server: + +.. code-block:: python3 from curio import run, tcp_server @@ -322,7 +330,9 @@ echo server:: run(tcp_server, '', 25000, echo_client) Run this program and connect to it using ``nc`` or ``telnet``. You'll -see the program echoing back data to you:: +see the program echoing back data to you: + +.. code-block:: console bash % nc localhost 25000 Hello (you type)