Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use formal method names when called internally #683

Merged
merged 1 commit into from
Aug 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions jupyter_client/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ async def _async_finish_shutdown(
except asyncio.TimeoutError:
self.log.debug("Kernel is taking too long to finish, terminating")
self._shutdown_status = _ShutdownStatus.SigtermRequest
await self._async_send_kernel_sigterm()
await ensure_async(self._send_kernel_sigterm())

try:
await asyncio.wait_for(
Expand Down Expand Up @@ -531,7 +531,7 @@ async def _async_interrupt_kernel(self) -> None:
assert self.kernel_spec is not None
interrupt_mode = self.kernel_spec.interrupt_mode
if interrupt_mode == "signal":
await self._async_signal_kernel(signal.SIGINT)
await ensure_async(self.signal_kernel(signal.SIGINT))

elif interrupt_mode == "message":
msg = self.session.msg("interrupt_request", content={})
Expand Down Expand Up @@ -574,7 +574,7 @@ async def _async_wait(self, pollinterval: float = 0.1) -> None:
# not alive. If we find the process is no longer alive, complete
# its cleanup via the blocking wait(). Callers are responsible for
# issuing calls to wait() using a timeout (see _kill_kernel()).
while await self._async_is_alive():
while await ensure_async(self.is_alive()):
await asyncio.sleep(pollinterval)


Expand Down
25 changes: 21 additions & 4 deletions jupyter_client/tests/test_kernelmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,13 +298,15 @@ def test_no_cleanup_shared_context(self, zmq_context):

def test_subclass_callables(self, km_subclass):
km_subclass.reset_counts()

km_subclass.start_kernel(stdout=PIPE, stderr=PIPE)
assert km_subclass.call_count("start_kernel") == 1
assert km_subclass.call_count("_launch_kernel") == 1

is_alive = km_subclass.is_alive()
assert is_alive
km_subclass.reset_counts()

km_subclass.restart_kernel(now=True)
assert km_subclass.call_count("restart_kernel") == 1
assert km_subclass.call_count("shutdown_kernel") == 1
Expand All @@ -313,26 +315,32 @@ def test_subclass_callables(self, km_subclass):
assert km_subclass.call_count("cleanup_resources") == 1
assert km_subclass.call_count("start_kernel") == 1
assert km_subclass.call_count("_launch_kernel") == 1
assert km_subclass.call_count("signal_kernel") == 1

is_alive = km_subclass.is_alive()
assert is_alive

assert km_subclass.call_count("is_alive") >= 1
km_subclass.reset_counts()

km_subclass.interrupt_kernel()
assert km_subclass.call_count("interrupt_kernel") == 1
assert km_subclass.call_count("signal_kernel") == 1

assert isinstance(km_subclass, KernelManager)

km_subclass.reset_counts()

km_subclass.shutdown_kernel(now=False)
assert km_subclass.call_count("shutdown_kernel") == 1
assert km_subclass.call_count("interrupt_kernel") == 1
assert km_subclass.call_count("request_shutdown") == 1
assert km_subclass.call_count("finish_shutdown") == 1
assert km_subclass.call_count("cleanup_resources") == 1
assert km_subclass.call_count("signal_kernel") == 1
assert km_subclass.call_count("is_alive") >= 1

is_alive = km_subclass.is_alive()
assert is_alive is False
assert km_subclass.call_count("is_alive") >= 1
assert km_subclass.context.closed


Expand Down Expand Up @@ -516,13 +524,16 @@ async def test_start_new_async_kernel(self, install_kernel, start_async_kernel):

async def test_subclass_callables(self, async_km_subclass):
async_km_subclass.reset_counts()

await async_km_subclass.start_kernel(stdout=PIPE, stderr=PIPE)
assert async_km_subclass.call_count("start_kernel") == 1
assert async_km_subclass.call_count("_launch_kernel") == 1

is_alive = await async_km_subclass.is_alive()
assert is_alive
assert async_km_subclass.call_count("is_alive") >= 1
async_km_subclass.reset_counts()

await async_km_subclass.restart_kernel(now=True)
assert async_km_subclass.call_count("restart_kernel") == 1
assert async_km_subclass.call_count("shutdown_kernel") == 1
Expand All @@ -531,24 +542,30 @@ async def test_subclass_callables(self, async_km_subclass):
assert async_km_subclass.call_count("cleanup_resources") == 1
assert async_km_subclass.call_count("start_kernel") == 1
assert async_km_subclass.call_count("_launch_kernel") == 1
assert async_km_subclass.call_count("signal_kernel") == 1

is_alive = await async_km_subclass.is_alive()
assert is_alive

assert async_km_subclass.call_count("is_alive") >= 1
async_km_subclass.reset_counts()

await async_km_subclass.interrupt_kernel()
assert async_km_subclass.call_count("interrupt_kernel") == 1
assert async_km_subclass.call_count("signal_kernel") == 1

assert isinstance(async_km_subclass, AsyncKernelManager)

async_km_subclass.reset_counts()

await async_km_subclass.shutdown_kernel(now=False)
assert async_km_subclass.call_count("shutdown_kernel") == 1
assert async_km_subclass.call_count("interrupt_kernel") == 1
assert async_km_subclass.call_count("request_shutdown") == 1
assert async_km_subclass.call_count("finish_shutdown") == 1
assert async_km_subclass.call_count("cleanup_resources") == 1
assert async_km_subclass.call_count("signal_kernel") == 1
assert async_km_subclass.call_count("is_alive") >= 1

is_alive = await async_km_subclass.is_alive()
assert is_alive is False
assert async_km_subclass.call_count("is_alive") >= 1
assert async_km_subclass.context.closed
12 changes: 12 additions & 0 deletions jupyter_client/tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,18 @@ def _kill_kernel(self):
def cleanup_resources(self, restart=False):
""" Record call and defer to superclass """

@subclass_recorder
def signal_kernel(self, signum: int):
""" Record call and defer to superclass """

@subclass_recorder
def is_alive(self):
""" Record call and defer to superclass """

@subclass_recorder
def _send_kernel_sigterm(self, restart: bool = False):
""" Record call and defer to superclass """


class SyncKMSubclass(KMSubclass, KernelManager):
"""Used to test subclass hierarchies to ensure methods are called when expected."""
Expand Down