summaryrefslogtreecommitdiffstats
path: root/Doc/library/asyncio-task.rst
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2013-12-03 00:22:06 (GMT)
committerVictor Stinner <victor.stinner@gmail.com>2013-12-03 00:22:06 (GMT)
commit3e09e32c8a9f4971b3fe89e9c20aa05fe4275bf1 (patch)
tree8b1e654856041311fb6cf51c674efd6147a46b1e /Doc/library/asyncio-task.rst
parentea3183f5b885f5e90be32e340966e7ef51a4cb67 (diff)
downloadcpython-3e09e32c8a9f4971b3fe89e9c20aa05fe4275bf1.zip
cpython-3e09e32c8a9f4971b3fe89e9c20aa05fe4275bf1.tar.gz
cpython-3e09e32c8a9f4971b3fe89e9c20aa05fe4275bf1.tar.bz2
asyncio doc: move coroutine example to the Task page
Diffstat (limited to 'Doc/library/asyncio-task.rst')
-rw-r--r--Doc/library/asyncio-task.rst23
1 files changed, 23 insertions, 0 deletions
diff --git a/Doc/library/asyncio-task.rst b/Doc/library/asyncio-task.rst
index 42a03d7..9541438 100644
--- a/Doc/library/asyncio-task.rst
+++ b/Doc/library/asyncio-task.rst
@@ -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>`.