Skip to content

Commit c9e2f1d

Browse files
committed
Remove deprecated cleanup() method and tests
1 parent f9092e8 commit c9e2f1d

File tree

4 files changed

+5
-85
lines changed

4 files changed

+5
-85
lines changed

jupyter_client/manager.py

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import signal
88
import sys
99
import typing as t
10-
import warnings
1110
from contextlib import contextmanager
1211
from enum import Enum
1312
from subprocess import Popen
@@ -19,7 +18,6 @@
1918
from traitlets import DottedObjectName
2019
from traitlets import Float
2120
from traitlets import Instance
22-
from traitlets import List
2321
from traitlets import observe
2422
from traitlets import observe_compat
2523
from traitlets import Type
@@ -410,15 +408,6 @@ def cleanup_resources(self, restart: bool = False) -> None:
410408
if self._created_context and not restart:
411409
self.context.destroy(linger=100)
412410

413-
def cleanup(self, connection_file: bool = True) -> None:
414-
"""Clean up resources when the kernel is shut down"""
415-
warnings.warn(
416-
"Method cleanup(connection_file=True) is deprecated, use cleanup_resources"
417-
"(restart=False).",
418-
FutureWarning,
419-
)
420-
self.cleanup_resources(restart=not connection_file)
421-
422411
async def _async_shutdown_kernel(self, now: bool = False, restart: bool = False):
423412
"""Attempts to stop the kernel process cleanly.
424413
@@ -452,28 +441,7 @@ async def _async_shutdown_kernel(self, now: bool = False, restart: bool = False)
452441
# most 1s, checking every 0.1s.
453442
await ensure_async(self.finish_shutdown())
454443

455-
# In 6.1.5, a new method, cleanup_resources(), was introduced to address
456-
# a leak issue (https://github.com/jupyter/jupyter_client/pull/548) and
457-
# replaced the existing cleanup() method. However, that method introduction
458-
# breaks subclass implementations that override cleanup() since it would
459-
# circumvent cleanup() functionality implemented in subclasses.
460-
# By detecting if the current instance overrides cleanup(), we can determine
461-
# if the deprecated path of calling cleanup() should be performed - which avoids
462-
# unnecessary deprecation warnings in a majority of configurations in which
463-
# subclassed KernelManager instances are not in use.
464-
# Note: because subclasses may have already implemented cleanup_resources()
465-
# but need to support older jupyter_clients, we should only take the deprecated
466-
# path if cleanup() is overridden but cleanup_resources() is not.
467-
468-
overrides_cleanup = type(self).cleanup is not KernelManager.cleanup
469-
overrides_cleanup_resources = (
470-
type(self).cleanup_resources is not KernelManager.cleanup_resources
471-
)
472-
473-
if overrides_cleanup and not overrides_cleanup_resources:
474-
self.cleanup(connection_file=not restart)
475-
else:
476-
self.cleanup_resources(restart=restart)
444+
self.cleanup_resources(restart=restart)
477445

478446
shutdown_kernel = run_sync(_async_shutdown_kernel)
479447

jupyter_client/multikernelmanager.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -272,10 +272,6 @@ def finish_shutdown(
272272
"""Wait for a kernel to finish shutting down, and kill it if it doesn't"""
273273
self.log.info("Kernel shutdown: %s" % kernel_id)
274274

275-
@kernel_method
276-
def cleanup(self, kernel_id: str, connection_file: bool = True) -> None:
277-
"""Clean up a kernel's resources"""
278-
279275
@kernel_method
280276
def cleanup_resources(self, kernel_id: str, restart: bool = False) -> None:
281277
"""Clean up a kernel's resources"""

jupyter_client/tests/test_kernelmanager.py

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
from ..manager import _ShutdownStatus
2020
from ..manager import start_new_async_kernel
2121
from ..manager import start_new_kernel
22-
from .utils import AsyncKernelManagerWithCleanup
2322
from .utils import AsyncKMSubclass
2423
from .utils import SyncKMSubclass
2524
from .utils import test_env
@@ -123,7 +122,7 @@ def zmq_context():
123122
ctx.term()
124123

125124

126-
@pytest.fixture(params=[AsyncKernelManager, AsyncKMSubclass, AsyncKernelManagerWithCleanup])
125+
@pytest.fixture(params=[AsyncKernelManager, AsyncKMSubclass])
127126
def async_km(request, config):
128127
km = request.param(config=config)
129128
return km
@@ -467,23 +466,6 @@ async def test_get_connect_info(self, async_km):
467466
)
468467
assert keys == expected
469468

470-
async def test_subclass_deprecations(self, async_km):
471-
await async_km.start_kernel(stdout=PIPE, stderr=PIPE)
472-
is_alive = await async_km.is_alive()
473-
assert is_alive
474-
assert isinstance(async_km, AsyncKernelManager)
475-
await async_km.shutdown_kernel(now=True)
476-
is_alive = await async_km.is_alive()
477-
assert is_alive is False
478-
assert async_km.context.closed
479-
480-
if isinstance(async_km, AsyncKernelManagerWithCleanup):
481-
assert async_km.which_cleanup == "cleanup"
482-
elif isinstance(async_km, AsyncKMSubclass):
483-
assert async_km.which_cleanup == "cleanup_resources"
484-
else:
485-
assert hasattr(async_km, "which_cleanup") is False
486-
487469
@pytest.mark.timeout(10)
488470
@pytest.mark.skipif(sys.platform == "win32", reason="Windows doesn't support signals")
489471
async def test_signal_kernel_subprocesses(self, install_kernel, start_async_kernel):

jupyter_client/tests/utils.py

Lines changed: 3 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -147,41 +147,15 @@ def cleanup_resources(self, restart=False):
147147

148148

149149
class SyncKMSubclass(KMSubclass, KernelManager):
150+
"""Used to test subclass hierarchies to ensure methods are called when expected."""
151+
150152
_superclass = KernelManager
151153

152154

153155
class AsyncKMSubclass(KMSubclass, AsyncKernelManager):
154-
"""Used to test subclass hierarchies to ensure methods are called when expected.
155-
156-
This class is also used to test deprecation "routes" that are determined by superclass'
157-
detection of methods.
158-
159-
This class represents a current subclass that overrides "interesting" methods of
160-
AsyncKernelManager.
161-
"""
156+
"""Used to test subclass hierarchies to ensure methods are called when expected."""
162157

163158
_superclass = AsyncKernelManager
164-
which_cleanup = "" # cleanup deprecation testing
165-
166-
@subclass_recorder
167-
def cleanup(self, connection_file=True):
168-
self.which_cleanup = "cleanup"
169-
170-
@subclass_recorder
171-
def cleanup_resources(self, restart=False):
172-
self.which_cleanup = "cleanup_resources"
173-
174-
175-
class AsyncKernelManagerWithCleanup(AsyncKernelManager):
176-
"""Used to test deprecation "routes" that are determined by superclass' detection of methods.
177-
178-
This class represents the older subclass that overrides cleanup(). We should find that
179-
cleanup() is called on these instances via TestAsyncKernelManagerWithCleanup.
180-
"""
181-
182-
def cleanup(self, connection_file=True):
183-
super().cleanup(connection_file=connection_file)
184-
self.which_cleanup = "cleanup"
185159

186160

187161
class MKMSubclass(RecordCallMixin):

0 commit comments

Comments
 (0)