[Python-checkins] cpython: asyncio doc: move coroutine example to the Task page

victor.stinner python-checkins at python.org
Tue Dec 3 01:47:07 CET 2013


http://hg.python.org/cpython/rev/18ba60ac4174
changeset:   87725:18ba60ac4174
user:        Victor Stinner <victor.stinner at gmail.com>
date:        Tue Dec 03 01:22:06 2013 +0100
summary:
  asyncio doc: move coroutine example to the Task page

files:
  Doc/library/asyncio-eventloop.rst |  28 ++++++------------
  Doc/library/asyncio-task.rst      |  23 +++++++++++++++
  2 files changed, 32 insertions(+), 19 deletions(-)


diff --git a/Doc/library/asyncio-eventloop.rst b/Doc/library/asyncio-eventloop.rst
--- a/Doc/library/asyncio-eventloop.rst
+++ b/Doc/library/asyncio-eventloop.rst
@@ -144,6 +144,10 @@
    Return the current time, as a :class:`float` value, according to the
    event loop's internal clock.
 
+.. seealso::
+
+   The :func:`asyncio.sleep` function.
+
 
 Creating connections
 ^^^^^^^^^^^^^^^^^^^^
@@ -330,11 +334,10 @@
    Set the default executor used by :meth:`run_in_executor`.
 
 
-Examples
---------
+.. _asyncio-hello-world-callback:
 
-Hello World (callback)
-^^^^^^^^^^^^^^^^^^^^^^
+Example: Hello World (callback)
+-------------------------------
 
 Print ``Hello World`` every two seconds, using a callback::
 
@@ -348,20 +351,7 @@
     print_and_repeat(loop)
     loop.run_forever()
 
+.. seealso::
 
-Hello World (coroutine)
-^^^^^^^^^^^^^^^^^^^^^^^
+   :ref:`Hello World example using a coroutine <asyncio-hello-world-coroutine>`.
 
-Print ``Hello World`` every two seconds, using a coroutine::
-
-    import asyncio
-
-    @asyncio.coroutine
-    def greet_every_two_seconds():
-        while True:
-            print('Hello World')
-            yield from asyncio.sleep(2)
-
-    loop = asyncio.get_event_loop()
-    loop.run_until_complete(greet_every_two_seconds())
-
diff --git a/Doc/library/asyncio-task.rst b/Doc/library/asyncio-task.rst
--- a/Doc/library/asyncio-task.rst
+++ b/Doc/library/asyncio-task.rst
@@ -230,3 +230,26 @@
       This does not raise :exc:`TimeoutError`! Futures that aren't done when
       the timeout occurs are returned in the second set.
 
+
+.. _asyncio-hello-world-coroutine:
+
+Example: Hello World (coroutine)
+--------------------------------
+
+Print ``Hello World`` every two seconds, using a coroutine::
+
+    import asyncio
+
+    @asyncio.coroutine
+    def greet_every_two_seconds():
+        while True:
+            print('Hello World')
+            yield from asyncio.sleep(2)
+
+    loop = asyncio.get_event_loop()
+    loop.run_until_complete(greet_every_two_seconds())
+
+
+.. seealso::
+
+   :ref:`Hello World example using a callback <asyncio-hello-world-callback>`.

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list