diff options
author | Victor Stinner <victor.stinner@gmail.com> | 2014-01-28 22:32:40 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@gmail.com> | 2014-01-28 22:32:40 (GMT) |
commit | f40c66334d175b34143609c0926346c793d089b2 (patch) | |
tree | f8d17af3a741083b875354856edea4aaa3d5e17f | |
parent | 38b0d5a778c8e296374bd59e6f8bb840d317d6e0 (diff) | |
download | cpython-f40c66334d175b34143609c0926346c793d089b2.zip cpython-f40c66334d175b34143609c0926346c793d089b2.tar.gz cpython-f40c66334d175b34143609c0926346c793d089b2.tar.bz2 |
asyncio doc: close the loop at exit
-rw-r--r-- | Doc/library/asyncio-dev.rst | 1 | ||||
-rw-r--r-- | Doc/library/asyncio-stream.rst | 1 | ||||
-rw-r--r-- | Doc/library/asyncio-task.rst | 3 |
3 files changed, 5 insertions, 0 deletions
diff --git a/Doc/library/asyncio-dev.rst b/Doc/library/asyncio-dev.rst index 74bbc28..73cc38a 100644 --- a/Doc/library/asyncio-dev.rst +++ b/Doc/library/asyncio-dev.rst @@ -169,6 +169,7 @@ operations:: asyncio.async(test()) loop.run_forever() print("Pending tasks at exit: %s" % asyncio.Task.all_tasks(loop)) + loop.close() Expected output:: diff --git a/Doc/library/asyncio-stream.rst b/Doc/library/asyncio-stream.rst index 22733c1..b5ffdba 100644 --- a/Doc/library/asyncio-stream.rst +++ b/Doc/library/asyncio-stream.rst @@ -256,6 +256,7 @@ Simple example querying HTTP headers of the URL passed on the command line:: loop = asyncio.get_event_loop() task = asyncio.async(print_http_headers(url)) loop.run_until_complete(task) + loop.close() Usage:: diff --git a/Doc/library/asyncio-task.rst b/Doc/library/asyncio-task.rst index 81372c5..8630f82 100644 --- a/Doc/library/asyncio-task.rst +++ b/Doc/library/asyncio-task.rst @@ -107,6 +107,7 @@ Example chaining coroutines:: loop = asyncio.get_event_loop() loop.run_until_complete(print_sum(1, 2)) + loop.close() ``compute()`` is chained to ``print_sum()``: ``print_sum()`` coroutine waits until ``compute()`` is completed before returing its result. @@ -234,6 +235,7 @@ Example combining a :class:`Future` and a :ref:`coroutine function asyncio.Task(slow_operation(future)) loop.run_until_complete(future) print(future.result()) + loop.close() The coroutine function is responsible of the computation (which takes 1 second) and it stores the result into the future. The @@ -354,6 +356,7 @@ Example executing 3 tasks (A, B, C) in parallel:: loop = asyncio.get_event_loop() loop.run_until_complete(asyncio.wait(tasks)) + loop.close() Output:: |