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
@@ -57,9 +58,9 @@ def _test_get_event_loop_new_process__sub_proc():
5758 async def doit ():
5859 return 'hello'
5960
60- loop = asyncio .new_event_loop ()
61- asyncio .set_event_loop (loop )
62- return loop .run_until_complete (doit ())
61+ with contextlib . closing ( asyncio .new_event_loop ()) as loop :
62+ asyncio .set_event_loop (loop )
63+ return loop .run_until_complete (doit ())
6364
6465
6566class CoroLike :
@@ -2892,13 +2893,13 @@ async def main():
28922893 def test_get_running_loop_already_running (self ):
28932894 async def main ():
28942895 running_loop = asyncio .get_running_loop ()
2895- loop = asyncio .new_event_loop ()
2896- try :
2897- loop .run_forever ()
2898- except RuntimeError :
2899- pass
2900- else :
2901- self .fail ("RuntimeError not raised" )
2896+ with contextlib . closing ( asyncio .new_event_loop ()) as loop :
2897+ try :
2898+ loop .run_forever ()
2899+ except RuntimeError :
2900+ pass
2901+ else :
2902+ self .fail ("RuntimeError not raised" )
29022903
29032904 self .assertIs (asyncio .get_running_loop (), running_loop )
29042905
You can’t perform that action at this time.
0 commit comments