[Python-checkins] cpython (3.4): Closes #21921: Fix ResourceWarning in the asyncio examples: close the event
victor.stinner
python-checkins at python.org
Sat Jul 5 15:41:29 CEST 2014
http://hg.python.org/cpython/rev/f6827c6b1164
changeset: 91554:f6827c6b1164
branch: 3.4
parent: 91552:d7e4efd5e279
user: Victor Stinner <victor.stinner at gmail.com>
date: Sat Jul 05 15:38:59 2014 +0200
summary:
Closes #21921: Fix ResourceWarning in the asyncio examples: close the event
loop at exit. Patch written by Vajrasky Kok (I modified also the "hello world"
example using a coroutine).
files:
Doc/library/asyncio-eventloop.rst | 10 ++++++++--
Doc/library/asyncio-task.rst | 5 ++++-
2 files changed, 12 insertions(+), 3 deletions(-)
diff --git a/Doc/library/asyncio-eventloop.rst b/Doc/library/asyncio-eventloop.rst
--- a/Doc/library/asyncio-eventloop.rst
+++ b/Doc/library/asyncio-eventloop.rst
@@ -651,7 +651,10 @@
loop = asyncio.get_event_loop()
loop.call_soon(print_and_repeat, loop)
- loop.run_forever()
+ try:
+ loop.run_forever()
+ finally:
+ loop.close()
.. seealso::
@@ -679,5 +682,8 @@
print("Event loop running forever, press CTRL+c to interrupt.")
print("pid %s: send SIGINT or SIGTERM to exit." % os.getpid())
- loop.run_forever()
+ try:
+ loop.run_forever()
+ finally:
+ loop.close()
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
@@ -89,7 +89,10 @@
yield from asyncio.sleep(2)
loop = asyncio.get_event_loop()
- loop.run_until_complete(greet_every_two_seconds())
+ try:
+ loop.run_until_complete(greet_every_two_seconds())
+ finally:
+ loop.close()
.. seealso::
--
Repository URL: http://hg.python.org/cpython
More information about the Python-checkins
mailing list