Kaydet (Commit) 63b21a8f authored tarafından Victor Stinner's avatar Victor Stinner

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).
üst a9acbe82
......@@ -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()
......@@ -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::
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment