diff options
author | Victor Stinner <victor.stinner@gmail.com> | 2013-12-03 00:22:06 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@gmail.com> | 2013-12-03 00:22:06 (GMT) |
commit | 3e09e32c8a9f4971b3fe89e9c20aa05fe4275bf1 (patch) | |
tree | 8b1e654856041311fb6cf51c674efd6147a46b1e /Doc | |
parent | ea3183f5b885f5e90be32e340966e7ef51a4cb67 (diff) | |
download | cpython-3e09e32c8a9f4971b3fe89e9c20aa05fe4275bf1.zip cpython-3e09e32c8a9f4971b3fe89e9c20aa05fe4275bf1.tar.gz cpython-3e09e32c8a9f4971b3fe89e9c20aa05fe4275bf1.tar.bz2 |
asyncio doc: move coroutine example to the Task page
Diffstat (limited to 'Doc')
-rw-r--r-- | Doc/library/asyncio-eventloop.rst | 28 | ||||
-rw-r--r-- | 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 index 708a429..eef9aa1 100644 --- a/Doc/library/asyncio-eventloop.rst +++ b/Doc/library/asyncio-eventloop.rst @@ -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>`. 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>`. |