mirror of
https://github.com/python/cpython.git
synced 2025-11-01 18:51:43 +00:00
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).
This commit is contained in:
parent
a9acbe82e7
commit
63b21a8ffa
2 changed files with 12 additions and 3 deletions
|
|
@ -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::
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue