diff options
author | Victor Stinner <victor.stinner@gmail.com> | 2014-07-05 13:38:59 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@gmail.com> | 2014-07-05 13:38:59 (GMT) |
commit | 63b21a8ffafcf40bb19a2d1be5c9fcdd487363a7 (patch) | |
tree | ac389dd9dc117d4ca7f70ad84581ec93879fd3f0 | |
parent | a9acbe82e7822e555b669139fdd8a7cb7667492c (diff) | |
download | cpython-63b21a8ffafcf40bb19a2d1be5c9fcdd487363a7.zip cpython-63b21a8ffafcf40bb19a2d1be5c9fcdd487363a7.tar.gz cpython-63b21a8ffafcf40bb19a2d1be5c9fcdd487363a7.tar.bz2 |
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).
-rw-r--r-- | Doc/library/asyncio-eventloop.rst | 10 | ||||
-rw-r--r-- | 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 index c242fc3..268fa41 100644 --- a/Doc/library/asyncio-eventloop.rst +++ b/Doc/library/asyncio-eventloop.rst @@ -651,7 +651,10 @@ Print ``Hello World`` every two seconds, using a callback:: 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 @@ Register handlers for signals :py:data:`SIGINT` and :py:data:`SIGTERM`:: 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 index f1894da..3544657 100644 --- a/Doc/library/asyncio-task.rst +++ b/Doc/library/asyncio-task.rst @@ -89,7 +89,10 @@ Print ``"Hello World"`` every two seconds using a coroutine:: 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:: |