Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6b90f9c

Browse files
committed
Switch out off deprecated asyncio.get_event_loop call
1 parent 66843b1 commit 6b90f9c

6 files changed

Lines changed: 19 additions & 14 deletions

File tree

IPython/core/async_helpers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def __call__(self, coro):
2525
"""
2626
import asyncio
2727

28-
return asyncio.get_event_loop().run_until_complete(coro)
28+
return asyncio.get_event_loop_policy().get_event_loop().run_until_complete(coro)
2929

3030
def __str__(self):
3131
return 'asyncio'

IPython/core/magics/script.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def safe_watcher():
8181
yield
8282
return
8383

84-
loop = asyncio.get_event_loop()
84+
loop = policy.get_event_loop()
8585
try:
8686
watcher = asyncio.SafeChildWatcher()
8787
watcher.attach_loop(loop)
@@ -238,7 +238,7 @@ async def _stream_communicate(process, cell):
238238

239239
if sys.platform.startswith("win"):
240240
asyncio.set_event_loop_policy(asyncio.WindowsProactorEventLoopPolicy())
241-
loop = asyncio.get_event_loop()
241+
loop = asyncio.get_event_loop_policy().get_event_loop()
242242
argv = arg_split(line, posix=not sys.platform.startswith("win"))
243243
args, cmd = self.shebang.parser.parse_known_args(argv)
244244
try:

IPython/core/tests/test_interactiveshell.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1039,7 +1039,7 @@ def test_custom_exc_count():
10391039

10401040

10411041
def test_run_cell_async():
1042-
loop = asyncio.get_event_loop()
1042+
loop = asyncio.get_event_loop_policy().get_event_loop()
10431043
ip.run_cell("import asyncio")
10441044
coro = ip.run_cell_async("await asyncio.sleep(0.01)\n5")
10451045
assert asyncio.iscoroutine(coro)

IPython/core/tests/test_magic.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -967,17 +967,22 @@ def test_script_config():
967967
assert "whoda" in sm.magics["cell"]
968968

969969

970+
@pytest.fixture
971+
def event_loop():
972+
yield asyncio.get_event_loop_policy().get_event_loop()
973+
974+
970975
@dec.skip_iptest_but_not_pytest
971976
@dec.skip_win32
972977
@pytest.mark.skipif(
973978
sys.platform == "win32", reason="This test does not run under Windows"
974979
)
975-
def test_script_out():
976-
assert asyncio.get_event_loop().is_running() is False
980+
def test_script_out(event_loop):
981+
assert event_loop.is_running() is False
977982

978983
ip = get_ipython()
979984
ip.run_cell_magic("script", "--out output sh", "echo 'hi'")
980-
assert asyncio.get_event_loop().is_running() is False
985+
assert event_loop.is_running() is False
981986
assert ip.user_ns["output"] == "hi\n"
982987

983988

@@ -986,11 +991,11 @@ def test_script_out():
986991
@pytest.mark.skipif(
987992
sys.platform == "win32", reason="This test does not run under Windows"
988993
)
989-
def test_script_err():
994+
def test_script_err(event_loop):
990995
ip = get_ipython()
991-
assert asyncio.get_event_loop().is_running() is False
996+
assert event_loop.is_running() is False
992997
ip.run_cell_magic("script", "--err error sh", "echo 'hello' >&2")
993-
assert asyncio.get_event_loop().is_running() is False
998+
assert event_loop.is_running() is False
994999
assert ip.user_ns["error"] == "hello\n"
9951000

9961001

@@ -1014,12 +1019,12 @@ def test_script_out_err():
10141019
@pytest.mark.skipif(
10151020
sys.platform == "win32", reason="This test does not run under Windows"
10161021
)
1017-
async def test_script_bg_out():
1022+
async def test_script_bg_out(event_loop):
10181023
ip = get_ipython()
10191024
ip.run_cell_magic("script", "--bg --out output sh", "echo 'hi'")
10201025
assert (await ip.user_ns["output"].read()) == b"hi\n"
10211026
ip.user_ns["output"].close()
1022-
asyncio.get_event_loop().stop()
1027+
event_loop.stop()
10231028

10241029

10251030
@dec.skip_iptest_but_not_pytest

IPython/terminal/interactiveshell.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -648,7 +648,7 @@ def enable_gui(self, gui=None):
648648
# When we integrate the asyncio event loop, run the UI in the
649649
# same event loop as the rest of the code. don't use an actual
650650
# input hook. (Asyncio is not made for nesting event loops.)
651-
self.pt_loop = asyncio.get_event_loop()
651+
self.pt_loop = asyncio.get_event_loop_policy().get_event_loop()
652652

653653
elif self._inputhook:
654654
# If an inputhook was set, create a new asyncio event loop with

IPython/terminal/pt_inputhooks/asyncio.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535

3636
# Keep reference to the original asyncio loop, because getting the event loop
3737
# within the input hook would return the other loop.
38-
loop = asyncio.get_event_loop()
38+
loop = asyncio.get_event_loop_policy().get_event_loop()
3939

4040

4141
def inputhook(context):

0 commit comments

Comments
 (0)