| 1 |
"""Tests for the KernelManager""" |
| 2 |
|
| 3 |
# Copyright (c) Jupyter Development Team. |
| 4 |
# Distributed under the terms of the Modified BSD License. |
| 5 |
import asyncio |
| 6 |
import concurrent.futures |
| 7 |
import json |
| 8 |
import os |
| 9 |
import signal |
| 10 |
import sys |
| 11 |
import sysconfig |
| 12 |
import time |
| 13 |
from subprocess import PIPE |
| 14 |
|
| 15 |
import pytest |
| 16 |
from jupyter_core import paths |
| 17 |
from traitlets.config.loader import Config |
| 18 |
|
| 19 |
from jupyter_client import AsyncKernelManager, KernelManager |
| 20 |
from jupyter_client.manager import _ShutdownStatus, start_new_async_kernel, start_new_kernel |
| 21 |
|
| 22 |
from .utils import AsyncKMSubclass, SyncKMSubclass |
| 23 |
|
| 24 |
pjoin = os.path.join |
| 25 |
|
| 26 |
TIMEOUT = 120 |
| 27 |
|
| 28 |
|
| 29 |
is_freethreaded = bool(sysconfig.get_config_var("Py_GIL_DISABLED")) |
| 30 |
|
| 31 |
|
| 32 |
@pytest.fixture(params=["tcp", "ipc"]) |
| 33 |
def transport(request): |
| 34 |
if sys.platform == "win32" and request.param == "ipc": # |
| 35 |
pytest.skip("Transport 'ipc' not supported on Windows.") |
| 36 |
return request.param |
| 37 |
|
| 38 |
|
| 39 |
@pytest.fixture |
| 40 |
def config(transport): |
| 41 |
c = Config() |
| 42 |
c.KernelManager.transport = transport |
| 43 |
if transport == "ipc": |
| 44 |
c.KernelManager.ip = "test" |
| 45 |
return c |
| 46 |
|
| 47 |
|
| 48 |
def _install_kernel(name="signaltest", extra_env=None): |
| 49 |
if extra_env is None: |
| 50 |
extra_env = {} |
| 51 |
kernel_dir = pjoin(paths.jupyter_data_dir(), "kernels", name) |
| 52 |
os.makedirs(kernel_dir, exist_ok=True) |
| 53 |
with open(pjoin(kernel_dir, "kernel.json"), "w") as f: |
| 54 |
f.write( |
| 55 |
json.dumps( |
| 56 |
{ |
| 57 |
"argv": [ |
| 58 |
sys.executable, |
| 59 |
"-m", |
| 60 |
"tests.signalkernel", |
| 61 |
"-f", |
| 62 |
"{connection_file}", |
| 63 |
], |
| 64 |
"display_name": "Signal Test Kernel", |
| 65 |
"env": {"TEST_VARS": "${TEST_VARS}:test_var_2", **extra_env}, |
| 66 |
} |
| 67 |
) |
| 68 |
) |
| 69 |
|
| 70 |
|
| 71 |
@pytest.fixture |
| 72 |
def install_kernel(): |
| 73 |
return _install_kernel() |
| 74 |
|
| 75 |
|
| 76 |
def install_kernel_dont_shutdown(): |
| 77 |
_install_kernel("signaltest-no-shutdown", {"NO_SHUTDOWN_REPLY": "1"}) |
| 78 |
|
| 79 |
|
| 80 |
def install_kernel_dont_terminate(): |
| 81 |
return _install_kernel( |
| 82 |
"signaltest-no-terminate", {"NO_SHUTDOWN_REPLY": "1", "NO_SIGTERM_REPLY": "1"} |
| 83 |
) |
| 84 |
|
| 85 |
|
| 86 |
@pytest.fixture |
| 87 |
def km(config): |
| 88 |
km = KernelManager(config=config) |
| 89 |
return km |
| 90 |
|
| 91 |
|
| 92 |
@pytest.fixture |
| 93 |
def km_subclass(config): |
| 94 |
km = SyncKMSubclass(config=config) |
| 95 |
return km |
| 96 |
|
| 97 |
|
| 98 |
@pytest.fixture(params=[AsyncKernelManager, AsyncKMSubclass]) |
| 99 |
def async_km(request, config): |
| 100 |
km = request.param(config=config) |
| 101 |
return km |
| 102 |
|
| 103 |
|
| 104 |
@pytest.fixture |
| 105 |
def async_km_subclass(config): |
| 106 |
km = AsyncKMSubclass(config=config) |
| 107 |
return km |
| 108 |
|
| 109 |
|
| 110 |
class TestKernelManagerShutDownGracefully: |
| 111 |
parameters = ( |
| 112 |
"name, install, expected", |
| 113 |
[ |
| 114 |
("signaltest", _install_kernel, _ShutdownStatus.ShutdownRequest), |
| 115 |
( |
| 116 |
"signaltest-no-shutdown", |
| 117 |
install_kernel_dont_shutdown, |
| 118 |
_ShutdownStatus.SigtermRequest, |
| 119 |
), |
| 120 |
( |
| 121 |
"signaltest-no-terminate", |
| 122 |
install_kernel_dont_terminate, |
| 123 |
_ShutdownStatus.SigkillRequest, |
| 124 |
), |
| 125 |
], |
| 126 |
) |
| 127 |
|
| 128 |
@pytest.mark.skipif(sys.platform == "win32", reason="Windows doesn't support signals") |
| 129 |
@pytest.mark.parametrize(*parameters) |
| 130 |
def test_signal_kernel_subprocesses(self, name, install, expected): |
| 131 |
install() |
| 132 |
km, kc = start_new_kernel(kernel_name=name) |
| 133 |
assert km._shutdown_status == _ShutdownStatus.Unset |
| 134 |
assert km.is_alive() |
| 135 |
# kc.execute("1") |
| 136 |
kc.stop_channels() |
| 137 |
km.shutdown_kernel() |
| 138 |
|
| 139 |
if expected == _ShutdownStatus.ShutdownRequest: |
| 140 |
expected = [expected, _ShutdownStatus.SigtermRequest] |
| 141 |
else: |
| 142 |
expected = [expected] |
| 143 |
|
| 144 |
assert km._shutdown_status in expected |
| 145 |
|
| 146 |
@pytest.mark.skipif(sys.platform == "win32", reason="Windows doesn't support signals") |
| 147 |
@pytest.mark.parametrize(*parameters) |
| 148 |
async def test_async_signal_kernel_subprocesses(self, name, install, expected): |
| 149 |
install() |
| 150 |
km, kc = await start_new_async_kernel(kernel_name=name) |
| 151 |
assert km._shutdown_status == _ShutdownStatus.Unset |
| 152 |
assert await km.is_alive() |
| 153 |
# kc.execute("1") |
| 154 |
kc.stop_channels() |
| 155 |
await km.shutdown_kernel() |
| 156 |
|
| 157 |
if expected == _ShutdownStatus.ShutdownRequest: |
| 158 |
expected = [expected, _ShutdownStatus.SigtermRequest] |
| 159 |
else: |
| 160 |
expected = [expected] |
| 161 |
|
| 162 |
assert km._shutdown_status in expected |
| 163 |
|
| 164 |
|
| 165 |
class TestKernelManager: |
| 166 |
def test_lifecycle(self, km): |
| 167 |
km.start_kernel(stdout=PIPE, stderr=PIPE) |
| 168 |
kc = km.client() |
| 169 |
assert km.is_alive() |
| 170 |
is_done = km.ready.done() |
| 171 |
assert is_done |
| 172 |
km.restart_kernel(now=True) |
| 173 |
assert km.is_alive() |
| 174 |
km.interrupt_kernel() |
| 175 |
assert isinstance(km, KernelManager) |
| 176 |
kc.stop_channels() |
| 177 |
km.shutdown_kernel(now=True) |
| 178 |
assert km.context.closed |
| 179 |
|
| 180 |
def test_get_connect_info(self, km): |
| 181 |
cinfo = km.get_connection_info() |
| 182 |
keys = sorted(cinfo.keys()) |
| 183 |
expected = sorted( |
| 184 |
[ |
| 185 |
"ip", |
| 186 |
"transport", |
| 187 |
"hb_port", |
| 188 |
"shell_port", |
| 189 |
"stdin_port", |
| 190 |
"iopub_port", |
| 191 |
"control_port", |
| 192 |
"key", |
| 193 |
"signature_scheme", |
| 194 |
] |
| 195 |
) |
| 196 |
assert keys == expected |
| 197 |
|
| 198 |
@pytest.mark.skipif(sys.platform == "win32", reason="Windows doesn't support signals") |
| 199 |
async def test_signal_kernel_subprocesses(self, install_kernel, jp_start_kernel): |
| 200 |
km, kc = await jp_start_kernel("signaltest") |
| 201 |
|
| 202 |
async def execute(cmd): |
| 203 |
request_id = kc.execute(cmd) |
| 204 |
while True: |
| 205 |
reply = await kc.get_shell_msg(TIMEOUT) |
| 206 |
if reply["parent_header"]["msg_id"] == request_id: |
| 207 |
break |
| 208 |
content = reply["content"] |
| 209 |
assert content["status"] == "ok" |
| 210 |
return content |
| 211 |
|
| 212 |
N = 5 |
| 213 |
for i in range(N): |
| 214 |
await execute("start") |
| 215 |
time.sleep(1) # make sure subprocs stay up |
| 216 |
reply = await execute("check") |
| 217 |
assert reply["user_expressions"]["poll"] == [None] * N |
| 218 |
|
| 219 |
# start a job on the kernel to be interrupted |
| 220 |
kc.execute("sleep") |
| 221 |
time.sleep(1) # ensure sleep message has been handled before we interrupt |
| 222 |
await km.interrupt_kernel() |
| 223 |
reply = await kc.get_shell_msg(TIMEOUT) |
| 224 |
content = reply["content"] |
| 225 |
assert content["status"] == "ok" |
| 226 |
assert content["user_expressions"]["interrupted"] |
| 227 |
# wait up to 10s for subprocesses to handle signal |
| 228 |
for i in range(100): |
| 229 |
reply = await execute("check") |
| 230 |
if reply["user_expressions"]["poll"] != [-signal.SIGINT] * N: |
| 231 |
time.sleep(0.1) |
| 232 |
else: |
| 233 |
break |
| 234 |
# verify that subprocesses were interrupted |
| 235 |
assert reply["user_expressions"]["poll"] == [-signal.SIGINT] * N |
| 236 |
|
| 237 |
async def test_start_new_kernel(self, install_kernel, jp_start_kernel): |
| 238 |
km, kc = await jp_start_kernel("signaltest") |
| 239 |
assert await km.is_alive() |
| 240 |
assert await kc.is_alive() |
| 241 |
assert km.context.closed is False |
| 242 |
|
| 243 |
async def _env_test_body(self, kc): |
| 244 |
async def execute(cmd): |
| 245 |
request_id = kc.execute(cmd) |
| 246 |
while True: |
| 247 |
reply = await kc.get_shell_msg(TIMEOUT) |
| 248 |
if reply["parent_header"]["msg_id"] == request_id: |
| 249 |
break |
| 250 |
content = reply["content"] |
| 251 |
assert content["status"] == "ok" |
| 252 |
return content |
| 253 |
|
| 254 |
reply = await execute("env") |
| 255 |
assert reply is not None |
| 256 |
assert reply["user_expressions"]["env"] == "${TEST_VARS}:test_var_2" |
| 257 |
|
| 258 |
async def test_templated_kspec_env(self, install_kernel, jp_start_kernel): |
| 259 |
km, kc = await jp_start_kernel("signaltest") |
| 260 |
assert await km.is_alive() |
| 261 |
assert await kc.is_alive() |
| 262 |
assert km.context.closed is False |
| 263 |
await self._env_test_body(kc) |
| 264 |
|
| 265 |
def test_cleanup_context(self, km): |
| 266 |
assert km.context is not None |
| 267 |
km.cleanup_resources(restart=False) |
| 268 |
assert km.context.closed |
| 269 |
|
| 270 |
def test_no_cleanup_shared_context(self, jp_zmq_context): |
| 271 |
"""kernel manager does not terminate shared context""" |
| 272 |
km = KernelManager(context=jp_zmq_context) |
| 273 |
assert km.context == jp_zmq_context |
| 274 |
assert km.context is not None |
| 275 |
|
| 276 |
km.cleanup_resources(restart=False) |
| 277 |
assert km.context.closed is False |
| 278 |
assert jp_zmq_context.closed is False |
| 279 |
|
| 280 |
def test_subclass_callables(self, km_subclass: SyncKMSubclass) -> None: |
| 281 |
km_subclass.reset_counts() |
| 282 |
|
| 283 |
km_subclass.start_kernel(stdout=PIPE, stderr=PIPE) |
| 284 |
assert km_subclass.call_count("start_kernel") == 1 |
| 285 |
assert km_subclass.call_count("_async_launch_kernel") == 1 |
| 286 |
|
| 287 |
is_alive = km_subclass.is_alive() |
| 288 |
assert is_alive |
| 289 |
km_subclass.reset_counts() |
| 290 |
|
| 291 |
km_subclass.restart_kernel(now=True) |
| 292 |
assert km_subclass.call_count("restart_kernel") == 1 |
| 293 |
assert km_subclass.call_count("_async_shutdown_kernel") == 1 |
| 294 |
assert km_subclass.call_count("_async_interrupt_kernel") == 1 |
| 295 |
assert km_subclass.call_count("_async_kill_kernel") == 1 |
| 296 |
assert km_subclass.call_count("_async_cleanup_resources") == 1 |
| 297 |
assert km_subclass.call_count("_async_launch_kernel") == 1 |
| 298 |
assert km_subclass.call_count("_async_signal_kernel") == 1 |
| 299 |
|
| 300 |
is_alive = km_subclass.is_alive() |
| 301 |
assert is_alive |
| 302 |
assert km_subclass.call_count("is_alive") >= 1 |
| 303 |
km_subclass.reset_counts() |
| 304 |
|
| 305 |
km_subclass.interrupt_kernel() |
| 306 |
assert km_subclass.call_count("_async_signal_kernel") == 1 |
| 307 |
|
| 308 |
assert isinstance(km_subclass, KernelManager) |
| 309 |
km_subclass.reset_counts() |
| 310 |
|
| 311 |
km_subclass.shutdown_kernel(now=False) |
| 312 |
assert km_subclass.call_count("shutdown_kernel") == 1 |
| 313 |
assert km_subclass.call_count("_async_interrupt_kernel") == 1 |
| 314 |
assert km_subclass.call_count("_async_cleanup_resources") == 1 |
| 315 |
assert km_subclass.call_count("_async_signal_kernel") == 1 |
| 316 |
assert km_subclass.call_count("_async_is_alive") >= 1 |
| 317 |
|
| 318 |
is_alive = km_subclass.is_alive() |
| 319 |
assert is_alive is False |
| 320 |
assert km_subclass.call_count("_async_is_alive") >= 1 |
| 321 |
assert km_subclass.context.closed |
| 322 |
|
| 323 |
|
| 324 |
class TestParallel: |
| 325 |
@pytest.mark.timeout(TIMEOUT) |
| 326 |
def test_start_sequence_kernels(self, config, install_kernel): |
| 327 |
"""Ensure that a sequence of kernel startups doesn't break anything.""" |
| 328 |
self._run_signaltest_lifecycle(config) |
| 329 |
self._run_signaltest_lifecycle(config) |
| 330 |
self._run_signaltest_lifecycle(config) |
| 331 |
|
| 332 |
@pytest.mark.xfail(is_freethreaded, reason="Fail on free-threaded python") |
| 333 |
@pytest.mark.timeout(TIMEOUT + 10) |
| 334 |
def test_start_parallel_thread_kernels(self, config, install_kernel): |
| 335 |
if config.KernelManager.transport == "ipc": # FIXME |
| 336 |
pytest.skip("IPC transport is currently not working for this test!") |
| 337 |
self._run_signaltest_lifecycle(config) |
| 338 |
|
| 339 |
with concurrent.futures.ThreadPoolExecutor(max_workers=2) as thread_executor: |
| 340 |
future1 = thread_executor.submit(self._run_signaltest_lifecycle, config) |
| 341 |
future2 = thread_executor.submit(self._run_signaltest_lifecycle, config) |
| 342 |
future1.result() |
| 343 |
future2.result() |
| 344 |
|
| 345 |
@pytest.mark.skipif(sys.version_info > (3, 14), reason="Zmq closing socket issues on 3.14+") |
| 346 |
@pytest.mark.timeout(TIMEOUT) |
| 347 |
def test_start_parallel_process_kernels(self, config, install_kernel): |
| 348 |
if config.KernelManager.transport in ("ipc", "tcp"): # FIXME |
| 349 |
pytest.skip("IPC/TCP transport is currently not working for this test!") |
| 350 |
self._run_signaltest_lifecycle(config) |
| 351 |
with concurrent.futures.ThreadPoolExecutor(max_workers=1) as thread_executor: |
| 352 |
future1 = thread_executor.submit(self._run_signaltest_lifecycle, config) |
| 353 |
with concurrent.futures.ProcessPoolExecutor(max_workers=1) as process_executor: |
| 354 |
future2 = process_executor.submit(self._run_signaltest_lifecycle, config) |
| 355 |
future2.result() |
| 356 |
future1.result() |
| 357 |
|
| 358 |
@pytest.mark.timeout(TIMEOUT) |
| 359 |
def test_start_sequence_process_kernels(self, config, install_kernel): |
| 360 |
if config.KernelManager.transport == "ipc": # FIXME |
| 361 |
pytest.skip("IPC transport is currently not working for this test!") |
| 362 |
self._run_signaltest_lifecycle(config) |
| 363 |
with concurrent.futures.ProcessPoolExecutor(max_workers=1) as pool_executor: |
| 364 |
future = pool_executor.submit(self._run_signaltest_lifecycle, config) |
| 365 |
future.result() |
| 366 |
|
| 367 |
def _prepare_kernel(self, km, startup_timeout=TIMEOUT, **kwargs): |
| 368 |
km.start_kernel(**kwargs) |
| 369 |
kc = km.client() |
| 370 |
kc.start_channels() |
| 371 |
try: |
| 372 |
kc.wait_for_ready(timeout=startup_timeout) |
| 373 |
except RuntimeError: |
| 374 |
kc.stop_channels() |
| 375 |
km.shutdown_kernel() |
| 376 |
raise |
| 377 |
|
| 378 |
return kc |
| 379 |
|
| 380 |
def _run_signaltest_lifecycle(self, config=None): |
| 381 |
km = KernelManager(config=config, kernel_name="signaltest") |
| 382 |
kc = self._prepare_kernel(km, stdout=PIPE, stderr=PIPE) |
| 383 |
|
| 384 |
def execute(cmd): |
| 385 |
request_id = kc.execute(cmd) |
| 386 |
while True: |
| 387 |
reply = kc.get_shell_msg(TIMEOUT) |
| 388 |
if reply["parent_header"]["msg_id"] == request_id: |
| 389 |
break |
| 390 |
content = reply["content"] |
| 391 |
assert content["status"] == "ok" |
| 392 |
return content |
| 393 |
|
| 394 |
execute("start") |
| 395 |
assert km.is_alive() |
| 396 |
execute("check") |
| 397 |
assert km.is_alive() |
| 398 |
|
| 399 |
km.restart_kernel(now=True) |
| 400 |
assert km.is_alive() |
| 401 |
execute("check") |
| 402 |
|
| 403 |
km.shutdown_kernel() |
| 404 |
assert km.context.closed |
| 405 |
kc.stop_channels() |
| 406 |
# close the event loop, if there is one |
| 407 |
try: |
| 408 |
loop = asyncio.get_event_loop() |
| 409 |
except RuntimeError: |
| 410 |
pass |
| 411 |
else: |
| 412 |
loop.close() |
| 413 |
|
| 414 |
|
| 415 |
class TestAsyncKernelManager: |
| 416 |
async def test_lifecycle(self, async_km): |
| 417 |
await async_km.start_kernel(stdout=PIPE, stderr=PIPE) |
| 418 |
is_alive = await async_km.is_alive() |
| 419 |
assert is_alive |
| 420 |
is_ready = async_km.ready.done() |
| 421 |
assert is_ready |
| 422 |
await async_km.restart_kernel(now=True) |
| 423 |
is_alive = await async_km.is_alive() |
| 424 |
assert is_alive |
| 425 |
await async_km.interrupt_kernel() |
| 426 |
assert isinstance(async_km, AsyncKernelManager) |
| 427 |
await async_km.shutdown_kernel(now=True) |
| 428 |
is_alive = await async_km.is_alive() |
| 429 |
assert is_alive is False |
| 430 |
assert async_km.context.closed |
| 431 |
|
| 432 |
async def test_get_connect_info(self, async_km): |
| 433 |
cinfo = async_km.get_connection_info() |
| 434 |
keys = sorted(cinfo.keys()) |
| 435 |
expected = sorted( |
| 436 |
[ |
| 437 |
"ip", |
| 438 |
"transport", |
| 439 |
"hb_port", |
| 440 |
"shell_port", |
| 441 |
"stdin_port", |
| 442 |
"iopub_port", |
| 443 |
"control_port", |
| 444 |
"key", |
| 445 |
"signature_scheme", |
| 446 |
] |
| 447 |
) |
| 448 |
assert keys == expected |
| 449 |
|
| 450 |
@pytest.mark.timeout(60) |
| 451 |
@pytest.mark.skipif(sys.platform == "win32", reason="Windows doesn't support signals") |
| 452 |
async def test_signal_kernel_subprocesses(self, install_kernel, jp_start_kernel): |
| 453 |
km, kc = await jp_start_kernel("signaltest") |
| 454 |
|
| 455 |
async def execute(cmd): |
| 456 |
request_id = kc.execute(cmd) |
| 457 |
while True: |
| 458 |
reply = await kc.get_shell_msg(TIMEOUT) |
| 459 |
if reply["parent_header"]["msg_id"] == request_id: |
| 460 |
break |
| 461 |
content = reply["content"] |
| 462 |
assert content["status"] == "ok" |
| 463 |
return content |
| 464 |
|
| 465 |
# Ensure that shutdown_kernel and stop_channels are called at the end of the test. |
| 466 |
# Note: we cannot use addCleanup(<func>) for these since it doesn't prpperly handle |
| 467 |
# coroutines - which km.shutdown_kernel now is. |
| 468 |
N = 5 |
| 469 |
for i in range(N): |
| 470 |
await execute("start") |
| 471 |
await asyncio.sleep(1) # make sure subprocs stay up |
| 472 |
reply = await execute("check") |
| 473 |
assert reply["user_expressions"]["poll"] == [None] * N |
| 474 |
|
| 475 |
# start a job on the kernel to be interrupted |
| 476 |
request_id = kc.execute("sleep") |
| 477 |
await asyncio.sleep(1) # ensure sleep message has been handled before we interrupt |
| 478 |
await km.interrupt_kernel() |
| 479 |
while True: |
| 480 |
reply = await kc.get_shell_msg(TIMEOUT) |
| 481 |
if reply["parent_header"]["msg_id"] == request_id: |
| 482 |
break |
| 483 |
content = reply["content"] |
| 484 |
assert content["status"] == "ok" |
| 485 |
assert content["user_expressions"]["interrupted"] is True |
| 486 |
# wait up to 5s for subprocesses to handle signal |
| 487 |
for i in range(50): |
| 488 |
reply = await execute("check") |
| 489 |
if reply["user_expressions"]["poll"] != [-signal.SIGINT] * N: |
| 490 |
await asyncio.sleep(0.1) |
| 491 |
else: |
| 492 |
break |
| 493 |
# verify that subprocesses were interrupted |
| 494 |
assert reply["user_expressions"]["poll"] == [-signal.SIGINT] * N |
| 495 |
|
| 496 |
@pytest.mark.timeout(30) |
| 497 |
async def test_start_new_async_kernel(self, install_kernel, jp_start_kernel): |
| 498 |
km, kc = await jp_start_kernel("signaltest") |
| 499 |
is_alive = await km.is_alive() |
| 500 |
assert is_alive |
| 501 |
is_alive = await kc.is_alive() |
| 502 |
assert is_alive |
| 503 |
|
| 504 |
async def test_subclass_callables(self, async_km_subclass: AsyncKMSubclass) -> None: |
| 505 |
async_km_subclass.reset_counts() |
| 506 |
|
| 507 |
await async_km_subclass.start_kernel(stdout=PIPE, stderr=PIPE) |
| 508 |
assert async_km_subclass.call_count("start_kernel") == 1 |
| 509 |
assert async_km_subclass.call_count("_async_launch_kernel") == 1 |
| 510 |
|
| 511 |
is_alive = await async_km_subclass.is_alive() |
| 512 |
assert is_alive |
| 513 |
assert async_km_subclass.call_count("is_alive") >= 1 |
| 514 |
async_km_subclass.reset_counts() |
| 515 |
|
| 516 |
await async_km_subclass.restart_kernel(now=True) |
| 517 |
assert async_km_subclass.call_count("restart_kernel") == 1 |
| 518 |
assert async_km_subclass.call_count("_async_shutdown_kernel") == 1 |
| 519 |
assert async_km_subclass.call_count("_async_interrupt_kernel") == 1 |
| 520 |
assert async_km_subclass.call_count("_async_kill_kernel") == 1 |
| 521 |
assert async_km_subclass.call_count("_async_cleanup_resources") == 1 |
| 522 |
assert async_km_subclass.call_count("_async_launch_kernel") == 1 |
| 523 |
assert async_km_subclass.call_count("_async_signal_kernel") == 1 |
| 524 |
|
| 525 |
is_alive = await async_km_subclass.is_alive() |
| 526 |
assert is_alive |
| 527 |
assert async_km_subclass.call_count("is_alive") >= 1 |
| 528 |
async_km_subclass.reset_counts() |
| 529 |
|
| 530 |
await async_km_subclass.interrupt_kernel() |
| 531 |
assert async_km_subclass.call_count("interrupt_kernel") == 1 |
| 532 |
assert async_km_subclass.call_count("_async_signal_kernel") == 1 |
| 533 |
|
| 534 |
assert isinstance(async_km_subclass, AsyncKernelManager) |
| 535 |
async_km_subclass.reset_counts() |
| 536 |
|
| 537 |
await async_km_subclass.shutdown_kernel(now=False) |
| 538 |
assert async_km_subclass.call_count("shutdown_kernel") == 1 |
| 539 |
assert async_km_subclass.call_count("_async_interrupt_kernel") == 1 |
| 540 |
assert async_km_subclass.call_count("_async_cleanup_resources") == 1 |
| 541 |
assert async_km_subclass.call_count("_async_signal_kernel") == 1 |
| 542 |
assert async_km_subclass.call_count("_async_is_alive") >= 1 |
| 543 |
|
| 544 |
is_alive = await async_km_subclass.is_alive() |
| 545 |
assert is_alive is False |
| 546 |
assert async_km_subclass.call_count("_async_is_alive") >= 1 |
| 547 |
assert async_km_subclass.context.closed |