Skip to content

Commit acb0fad

Browse files
committed
-
1 parent f21dd29 commit acb0fad

File tree

5 files changed

+13
-26
lines changed

5 files changed

+13
-26
lines changed

ipykernel/kernelbase.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,15 @@ async def shell_main(self, subshell_id: str | None):
419419

420420
async with create_task_group() as tg:
421421
tg.start_soon(self.process_shell, socket)
422+
if subshell_id is None:
423+
# Main subshell.
424+
await to_thread.run_sync(self.shell_stop.wait)
425+
426+
if not self._eventloop_set.is_set():
427+
# Stop the async task that is waiting for the eventloop to be set.
428+
self._eventloop_set.set()
429+
430+
tg.cancel_scope.cancel()
422431

423432
async def process_shell(self, socket=None):
424433
# socket=None is valid if kernel subshells are not supported.
@@ -568,14 +577,6 @@ async def start(self, *, task_status: TaskStatus = TASK_STATUS_IGNORED) -> None:
568577
if not self._is_test and self.shell_socket is not None:
569578
tg.start_soon(self.shell_main, None)
570579

571-
await to_thread.run_sync(self.shell_stop.wait)
572-
573-
if not self._eventloop_set.is_set():
574-
# Stop the async task that is waiting for the eventloop to be set.
575-
self._eventloop_set.set()
576-
577-
tg.cancel_scope.cancel()
578-
579580
def stop(self):
580581
self.shell_stop.set()
581582
self.control_stop.set()

tests/conftest.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,6 @@
1919
from ipykernel.kernelbase import Kernel
2020
from ipykernel.zmqshell import ZMQInteractiveShell
2121

22-
# ensure we don't leak history managers
23-
if os.name != "nt":
24-
import tracemalloc
25-
26-
tracemalloc.start(20)
27-
HistoryManager._max_inst = 1
28-
2922

3023
@pytest.fixture(scope="session", autouse=True)
3124
def _garbage_collection(request):
@@ -43,6 +36,10 @@ def _garbage_collection(request):
4336
except ModuleNotFoundError:
4437
tracemalloc = None
4538

39+
# ensure we don't leak history managers
40+
if os.name != "nt":
41+
HistoryManager._max_inst = 1
42+
4643

4744
pytestmark = pytest.mark.anyio
4845

@@ -225,8 +222,6 @@ async def ipkernel(anyio_backend):
225222
yield kernel
226223
finally:
227224
kernel.destroy()
228-
kernel.shell._atexit_once()
229-
kernel.shell.configurables = []
230225
ZMQInteractiveShell.clear_instance()
231226

232227

tests/test_comm.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
from ipykernel.kernelbase import Kernel
88

99

10-
@pytest.mark.parametrize("anyio_backend", ["asyncio"])
1110
def test_comm(kernel: Kernel) -> None:
1211
manager = CommManager(kernel=kernel)
1312
kernel.comm_manager = manager # type:ignore
@@ -35,7 +34,6 @@ def on_message(msg):
3534
assert c.target_name == "bar"
3635

3736

38-
@pytest.mark.parametrize("anyio_backend", ["asyncio"])
3937
def test_comm_manager(kernel: Kernel) -> None:
4038
manager = CommManager(kernel=kernel)
4139
msgs = []
@@ -101,7 +99,6 @@ def on_msg(msg):
10199
assert comm._closed
102100

103101

104-
@pytest.mark.parametrize("anyio_backend", ["asyncio"])
105102
def test_comm_in_manager(ipkernel: IPythonKernel) -> None:
106103
with pytest.deprecated_call():
107104
comm = Comm()

tests/test_eventloop.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ def _setup_env():
5959

6060
@windows_skip
6161
@pytest.mark.skipif(sys.platform == "darwin", reason="hangs on macos")
62-
@pytest.mark.parametrize("anyio_backend", ["asyncio"])
6362
def test_tk_loop(kernel):
6463
def do_thing():
6564
time.sleep(1)
@@ -91,19 +90,16 @@ def do_thing():
9190

9291

9392
@windows_skip
94-
@pytest.mark.parametrize("anyio_backend", ["asyncio"])
9593
def test_enable_gui(kernel):
9694
enable_gui("tk", kernel)
9795

9896

9997
@pytest.mark.skipif(sys.platform != "darwin", reason="MacOS-only")
100-
@pytest.mark.parametrize("anyio_backend", ["asyncio"])
10198
def test_cocoa_loop(kernel):
10299
loop_cocoa(kernel)
103100

104101

105102
@pytest.mark.parametrize("gui", qt_guis_avail)
106-
@pytest.mark.parametrize("anyio_backend", ["asyncio"])
107103
def test_qt_enable_gui(gui, kernel, capsys):
108104
if os.getenv("GITHUB_ACTIONS", None) == "true" and gui == "qt5":
109105
pytest.skip("Qt5 and GitHub action crash CPython")

tests/test_zmq_shell.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,6 @@ def test_magics(tmp_path):
233233
socket.close()
234234
context.destroy()
235235
finally:
236-
shell._atexit_once()
237236
shell.configurables = []
238237
InteractiveShell.clear_instance()
239238

@@ -258,7 +257,6 @@ def test_zmq_interactive_shell(kernel):
258257
shell.system_piped("dir")
259258
shell.ask_exit()
260259
finally:
261-
shell._atexit_once()
262260
shell.configurables = []
263261
ZMQInteractiveShell.clear_instance()
264262

0 commit comments

Comments
 (0)