##// END OF EJS Templates
Switch out off deprecated `asyncio.get_event_loop` call
Nikita Kniazev -
Show More
@@ -25,7 +25,7 b' class _AsyncIORunner:'
25 """
25 """
26 import asyncio
26 import asyncio
27
27
28 return asyncio.get_event_loop().run_until_complete(coro)
28 return asyncio.get_event_loop_policy().get_event_loop().run_until_complete(coro)
29
29
30 def __str__(self):
30 def __str__(self):
31 return 'asyncio'
31 return 'asyncio'
@@ -81,7 +81,7 b' def safe_watcher():'
81 yield
81 yield
82 return
82 return
83
83
84 loop = asyncio.get_event_loop()
84 loop = policy.get_event_loop()
85 try:
85 try:
86 watcher = asyncio.SafeChildWatcher()
86 watcher = asyncio.SafeChildWatcher()
87 watcher.attach_loop(loop)
87 watcher.attach_loop(loop)
@@ -238,7 +238,7 b' class ScriptMagics(Magics):'
238
238
239 if sys.platform.startswith("win"):
239 if sys.platform.startswith("win"):
240 asyncio.set_event_loop_policy(asyncio.WindowsProactorEventLoopPolicy())
240 asyncio.set_event_loop_policy(asyncio.WindowsProactorEventLoopPolicy())
241 loop = asyncio.get_event_loop()
241 loop = asyncio.get_event_loop_policy().get_event_loop()
242 argv = arg_split(line, posix=not sys.platform.startswith("win"))
242 argv = arg_split(line, posix=not sys.platform.startswith("win"))
243 args, cmd = self.shebang.parser.parse_known_args(argv)
243 args, cmd = self.shebang.parser.parse_known_args(argv)
244 try:
244 try:
@@ -1039,7 +1039,7 b' def test_custom_exc_count():'
1039
1039
1040
1040
1041 def test_run_cell_async():
1041 def test_run_cell_async():
1042 loop = asyncio.get_event_loop()
1042 loop = asyncio.get_event_loop_policy().get_event_loop()
1043 ip.run_cell("import asyncio")
1043 ip.run_cell("import asyncio")
1044 coro = ip.run_cell_async("await asyncio.sleep(0.01)\n5")
1044 coro = ip.run_cell_async("await asyncio.sleep(0.01)\n5")
1045 assert asyncio.iscoroutine(coro)
1045 assert asyncio.iscoroutine(coro)
@@ -967,17 +967,22 b' def test_script_config():'
967 assert "whoda" in sm.magics["cell"]
967 assert "whoda" in sm.magics["cell"]
968
968
969
969
970 @pytest.fixture
971 def event_loop():
972 yield asyncio.get_event_loop_policy().get_event_loop()
973
974
970 @dec.skip_iptest_but_not_pytest
975 @dec.skip_iptest_but_not_pytest
971 @dec.skip_win32
976 @dec.skip_win32
972 @pytest.mark.skipif(
977 @pytest.mark.skipif(
973 sys.platform == "win32", reason="This test does not run under Windows"
978 sys.platform == "win32", reason="This test does not run under Windows"
974 )
979 )
975 def test_script_out():
980 def test_script_out(event_loop):
976 assert asyncio.get_event_loop().is_running() is False
981 assert event_loop.is_running() is False
977
982
978 ip = get_ipython()
983 ip = get_ipython()
979 ip.run_cell_magic("script", "--out output sh", "echo 'hi'")
984 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
981 assert ip.user_ns["output"] == "hi\n"
986 assert ip.user_ns["output"] == "hi\n"
982
987
983
988
@@ -986,11 +991,11 b' def test_script_out():'
986 @pytest.mark.skipif(
991 @pytest.mark.skipif(
987 sys.platform == "win32", reason="This test does not run under Windows"
992 sys.platform == "win32", reason="This test does not run under Windows"
988 )
993 )
989 def test_script_err():
994 def test_script_err(event_loop):
990 ip = get_ipython()
995 ip = get_ipython()
991 assert asyncio.get_event_loop().is_running() is False
996 assert event_loop.is_running() is False
992 ip.run_cell_magic("script", "--err error sh", "echo 'hello' >&2")
997 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
994 assert ip.user_ns["error"] == "hello\n"
999 assert ip.user_ns["error"] == "hello\n"
995
1000
996
1001
@@ -1014,12 +1019,12 b' def test_script_out_err():'
1014 @pytest.mark.skipif(
1019 @pytest.mark.skipif(
1015 sys.platform == "win32", reason="This test does not run under Windows"
1020 sys.platform == "win32", reason="This test does not run under Windows"
1016 )
1021 )
1017 async def test_script_bg_out():
1022 async def test_script_bg_out(event_loop):
1018 ip = get_ipython()
1023 ip = get_ipython()
1019 ip.run_cell_magic("script", "--bg --out output sh", "echo 'hi'")
1024 ip.run_cell_magic("script", "--bg --out output sh", "echo 'hi'")
1020 assert (await ip.user_ns["output"].read()) == b"hi\n"
1025 assert (await ip.user_ns["output"].read()) == b"hi\n"
1021 ip.user_ns["output"].close()
1026 ip.user_ns["output"].close()
1022 asyncio.get_event_loop().stop()
1027 event_loop.stop()
1023
1028
1024
1029
1025 @dec.skip_iptest_but_not_pytest
1030 @dec.skip_iptest_but_not_pytest
@@ -648,7 +648,7 b' class TerminalInteractiveShell(InteractiveShell):'
648 # When we integrate the asyncio event loop, run the UI in the
648 # When we integrate the asyncio event loop, run the UI in the
649 # same event loop as the rest of the code. don't use an actual
649 # same event loop as the rest of the code. don't use an actual
650 # input hook. (Asyncio is not made for nesting event loops.)
650 # 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()
652
652
653 elif self._inputhook:
653 elif self._inputhook:
654 # If an inputhook was set, create a new asyncio event loop with
654 # If an inputhook was set, create a new asyncio event loop with
@@ -35,7 +35,7 b" PTK3 = ptk_version.startswith('3.')"
35
35
36 # Keep reference to the original asyncio loop, because getting the event loop
36 # Keep reference to the original asyncio loop, because getting the event loop
37 # within the input hook would return the other loop.
37 # 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()
39
39
40
40
41 def inputhook(context):
41 def inputhook(context):
General Comments 0
You need to be logged in to leave comments. Login now