File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11"""Tests for events.py."""
22
33import concurrent .futures
4+ import contextlib
45import functools
56import io
67import multiprocessing
@@ -55,9 +56,9 @@ def _test_get_event_loop_new_process__sub_proc():
5556 async def doit ():
5657 return 'hello'
5758
58- loop = asyncio .new_event_loop ()
59- asyncio ._set_event_loop (loop )
60- return loop .run_until_complete (doit ())
59+ with contextlib . closing ( asyncio .new_event_loop ()) as loop :
60+ asyncio ._set_event_loop (loop )
61+ return loop .run_until_complete (doit ())
6162
6263
6364class CoroLike :
@@ -3005,13 +3006,13 @@ async def main():
30053006 def test_get_running_loop_already_running (self ):
30063007 async def main ():
30073008 running_loop = asyncio .get_running_loop ()
3008- loop = asyncio .new_event_loop ()
3009- try :
3010- loop .run_forever ()
3011- except RuntimeError :
3012- pass
3013- else :
3014- self .fail ("RuntimeError not raised" )
3009+ with contextlib . closing ( asyncio .new_event_loop ()) as loop :
3010+ try :
3011+ loop .run_forever ()
3012+ except RuntimeError :
3013+ pass
3014+ else :
3015+ self .fail ("RuntimeError not raised" )
30153016
30163017 self .assertIs (asyncio .get_running_loop (), running_loop )
30173018
You can’t perform that action at this time.
0 commit comments