summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2014-02-17 09:54:30 (GMT)
committerVictor Stinner <victor.stinner@gmail.com>2014-02-17 09:54:30 (GMT)
commit04e05da1b3ae3b3f1f7c2535860e156697c5b696 (patch)
tree9354ea79acfd503614d2b2b6262653af455f57a1
parenta91ff1423fbd57e7bd0853ac494d8cdea1fb5bb9 (diff)
downloadcpython-04e05da1b3ae3b3f1f7c2535860e156697c5b696.zip
cpython-04e05da1b3ae3b3f1f7c2535860e156697c5b696.tar.gz
cpython-04e05da1b3ae3b3f1f7c2535860e156697c5b696.tar.bz2
Close #20652: asyncio doc: close the event loop in run_forever() example. Fix
also typo. Patch written by Vajrasky Kok.
-rw-r--r--Doc/library/asyncio-task.rst9
1 files changed, 6 insertions, 3 deletions
diff --git a/Doc/library/asyncio-task.rst b/Doc/library/asyncio-task.rst
index 83d9742..e7ef172 100644
--- a/Doc/library/asyncio-task.rst
+++ b/Doc/library/asyncio-task.rst
@@ -229,7 +229,7 @@ Example combining a :class:`Future` and a :ref:`coroutine function
@asyncio.coroutine
def slow_operation(future):
yield from asyncio.sleep(1)
- future.set_result('Future in done!')
+ future.set_result('Future is done!')
loop = asyncio.get_event_loop()
future = asyncio.Future()
@@ -261,7 +261,7 @@ flow::
@asyncio.coroutine
def slow_operation(future):
yield from asyncio.sleep(1)
- future.set_result('Future in done!')
+ future.set_result('Future is done!')
def got_result(future):
print(future.result())
@@ -271,7 +271,10 @@ flow::
future = asyncio.Future()
asyncio.Task(slow_operation(future))
future.add_done_callback(got_result)
- loop.run_forever()
+ try:
+ loop.run_forever()
+ finally:
+ loop.close()
In this example, the future is responsible to display the result and to stop
the loop.