|
7 | 7 | import signal |
8 | 8 | import sys |
9 | 9 | import typing as t |
10 | | -import warnings |
11 | 10 | from contextlib import contextmanager |
12 | 11 | from enum import Enum |
13 | 12 | from subprocess import Popen |
|
19 | 18 | from traitlets import DottedObjectName |
20 | 19 | from traitlets import Float |
21 | 20 | from traitlets import Instance |
22 | | -from traitlets import List |
23 | 21 | from traitlets import observe |
24 | 22 | from traitlets import observe_compat |
25 | 23 | from traitlets import Type |
@@ -129,27 +127,6 @@ def kernel_spec(self) -> t.Optional[kernelspec.KernelSpec]: |
129 | 127 | self._kernel_spec = self.kernel_spec_manager.get_kernel_spec(self.kernel_name) |
130 | 128 | return self._kernel_spec |
131 | 129 |
|
132 | | - kernel_cmd: List = List( |
133 | | - Unicode(), |
134 | | - config=True, |
135 | | - help="""DEPRECATED: Use kernel_name instead. |
136 | | -
|
137 | | - The Popen Command to launch the kernel. |
138 | | - Override this if you have a custom kernel. |
139 | | - If kernel_cmd is specified in a configuration file, |
140 | | - Jupyter does not pass any arguments to the kernel, |
141 | | - because it cannot make any assumptions about the |
142 | | - arguments that the kernel understands. In particular, |
143 | | - this means that the kernel does not receive the |
144 | | - option --debug if it given on the Jupyter command line. |
145 | | - """, |
146 | | - ) |
147 | | - |
148 | | - def _kernel_cmd_changed(self, name, old, new): |
149 | | - warnings.warn( |
150 | | - "Setting kernel_cmd is deprecated, use kernel_spec to " "start different kernels." |
151 | | - ) |
152 | | - |
153 | 130 | cache_ports: Bool = Bool( |
154 | 131 | help="True if the MultiKernelManager should cache ports for this KernelManager instance" |
155 | 132 | ) |
@@ -226,11 +203,8 @@ def client(self, **kwargs) -> KernelClient: |
226 | 203 | def format_kernel_cmd(self, extra_arguments: t.Optional[t.List[str]] = None) -> t.List[str]: |
227 | 204 | """replace templated args (e.g. {connection_file})""" |
228 | 205 | extra_arguments = extra_arguments or [] |
229 | | - if self.kernel_cmd: |
230 | | - cmd = self.kernel_cmd + extra_arguments |
231 | | - else: |
232 | | - assert self.kernel_spec is not None |
233 | | - cmd = self.kernel_spec.argv + extra_arguments |
| 206 | + assert self.kernel_spec is not None |
| 207 | + cmd = self.kernel_spec.argv + extra_arguments |
234 | 208 |
|
235 | 209 | if cmd and cmd[0] in { |
236 | 210 | "python", |
@@ -324,11 +298,10 @@ def pre_start_kernel(self, **kw) -> t.Tuple[t.List[str], t.Dict[str, t.Any]]: |
324 | 298 | # Don't allow PYTHONEXECUTABLE to be passed to kernel process. |
325 | 299 | # If set, it can bork all the things. |
326 | 300 | env.pop("PYTHONEXECUTABLE", None) |
327 | | - if not self.kernel_cmd: |
328 | | - # If kernel_cmd has been set manually, don't refer to a kernel spec. |
329 | | - # Environment variables from kernel spec are added to os.environ. |
330 | | - assert self.kernel_spec is not None |
331 | | - env.update(self._get_env_substitutions(self.kernel_spec.env, env)) |
| 301 | + |
| 302 | + # Environment variables from kernel spec are added to os.environ. |
| 303 | + assert self.kernel_spec is not None |
| 304 | + env.update(self._get_env_substitutions(self.kernel_spec.env, env)) |
332 | 305 |
|
333 | 306 | kw["env"] = env |
334 | 307 | return kernel_cmd, kw |
@@ -435,15 +408,6 @@ def cleanup_resources(self, restart: bool = False) -> None: |
435 | 408 | if self._created_context and not restart: |
436 | 409 | self.context.destroy(linger=100) |
437 | 410 |
|
438 | | - def cleanup(self, connection_file: bool = True) -> None: |
439 | | - """Clean up resources when the kernel is shut down""" |
440 | | - warnings.warn( |
441 | | - "Method cleanup(connection_file=True) is deprecated, use cleanup_resources" |
442 | | - "(restart=False).", |
443 | | - FutureWarning, |
444 | | - ) |
445 | | - self.cleanup_resources(restart=not connection_file) |
446 | | - |
447 | 411 | async def _async_shutdown_kernel(self, now: bool = False, restart: bool = False): |
448 | 412 | """Attempts to stop the kernel process cleanly. |
449 | 413 |
|
@@ -477,28 +441,7 @@ async def _async_shutdown_kernel(self, now: bool = False, restart: bool = False) |
477 | 441 | # most 1s, checking every 0.1s. |
478 | 442 | await ensure_async(self.finish_shutdown()) |
479 | 443 |
|
480 | | - # In 6.1.5, a new method, cleanup_resources(), was introduced to address |
481 | | - # a leak issue (https://github.com/jupyter/jupyter_client/pull/548) and |
482 | | - # replaced the existing cleanup() method. However, that method introduction |
483 | | - # breaks subclass implementations that override cleanup() since it would |
484 | | - # circumvent cleanup() functionality implemented in subclasses. |
485 | | - # By detecting if the current instance overrides cleanup(), we can determine |
486 | | - # if the deprecated path of calling cleanup() should be performed - which avoids |
487 | | - # unnecessary deprecation warnings in a majority of configurations in which |
488 | | - # subclassed KernelManager instances are not in use. |
489 | | - # Note: because subclasses may have already implemented cleanup_resources() |
490 | | - # but need to support older jupyter_clients, we should only take the deprecated |
491 | | - # path if cleanup() is overridden but cleanup_resources() is not. |
492 | | - |
493 | | - overrides_cleanup = type(self).cleanup is not KernelManager.cleanup |
494 | | - overrides_cleanup_resources = ( |
495 | | - type(self).cleanup_resources is not KernelManager.cleanup_resources |
496 | | - ) |
497 | | - |
498 | | - if overrides_cleanup and not overrides_cleanup_resources: |
499 | | - self.cleanup(connection_file=not restart) |
500 | | - else: |
501 | | - self.cleanup_resources(restart=restart) |
| 444 | + self.cleanup_resources(restart=restart) |
502 | 445 |
|
503 | 446 | shutdown_kernel = run_sync(_async_shutdown_kernel) |
504 | 447 |
|
|
0 commit comments