[Python-checkins] cpython: asyncio doc: close the loop at exit

victor.stinner python-checkins at python.org
Tue Jan 28 23:33:12 CET 2014


http://hg.python.org/cpython/rev/824ba744b999
changeset:   88799:824ba744b999
user:        Victor Stinner <victor.stinner at gmail.com>
date:        Tue Jan 28 23:32:40 2014 +0100
summary:
  asyncio doc: close the loop at exit

files:
  Doc/library/asyncio-dev.rst    |  1 +
  Doc/library/asyncio-stream.rst |  1 +
  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
--- a/Doc/library/asyncio-dev.rst
+++ b/Doc/library/asyncio-dev.rst
@@ -169,6 +169,7 @@
     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
--- a/Doc/library/asyncio-stream.rst
+++ b/Doc/library/asyncio-stream.rst
@@ -256,6 +256,7 @@
     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
--- a/Doc/library/asyncio-task.rst
+++ b/Doc/library/asyncio-task.rst
@@ -107,6 +107,7 @@
 
     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 @@
     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 @@
 
     loop = asyncio.get_event_loop()
     loop.run_until_complete(asyncio.wait(tasks))
+    loop.close()
 
 Output::
 

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list