Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions Lib/test/test_asyncio/test_events.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Tests for events.py."""

import concurrent.futures
import contextlib
import functools
import io
import multiprocessing
Expand Down Expand Up @@ -57,9 +58,9 @@ def _test_get_event_loop_new_process__sub_proc():
async def doit():
return 'hello'

loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
return loop.run_until_complete(doit())
with contextlib.closing(asyncio.new_event_loop()) as loop:
asyncio.set_event_loop(loop)
return loop.run_until_complete(doit())


class CoroLike:
Expand Down Expand Up @@ -2892,13 +2893,13 @@ async def main():
def test_get_running_loop_already_running(self):
async def main():
running_loop = asyncio.get_running_loop()
loop = asyncio.new_event_loop()
try:
loop.run_forever()
except RuntimeError:
pass
else:
self.fail("RuntimeError not raised")
with contextlib.closing(asyncio.new_event_loop()) as loop:
try:
loop.run_forever()
except RuntimeError:
pass
else:
self.fail("RuntimeError not raised")

self.assertIs(asyncio.get_running_loop(), running_loop)

Expand Down
Loading