]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
asyncio doc: move coroutine example to the Task page
authorVictor Stinner <victor.stinner@gmail.com>
Tue, 3 Dec 2013 00:22:06 +0000 (01:22 +0100)
committerVictor Stinner <victor.stinner@gmail.com>
Tue, 3 Dec 2013 00:22:06 +0000 (01:22 +0100)
Doc/library/asyncio-eventloop.rst
Doc/library/asyncio-task.rst

index 708a429128eed4dffffc1f75e62e9c4b393f343c..eef9aa1c849460e4747560146de3bcb18802228e 100644 (file)
@@ -144,6 +144,10 @@ a different clock than :func:`time.time`.
    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 @@ pool of processes). By default, an event loop uses a thread pool executor
    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 ``Hello World`` every two seconds, using a callback::
     print_and_repeat(loop)
     loop.run_forever()
 
+.. seealso::
 
-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())
+   :ref:`Hello World example using a coroutine <asyncio-hello-world-coroutine>`.
 
index 42a03d77f332dc060bfbbb5f46b1b83f8a6d031b..954143883dcfb312d0ae1fadc93254f9aec7309e 100644 (file)
@@ -230,3 +230,26 @@ Task functions
       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>`.