|
23 | 23 |
|
24 | 24 | from enterprise_gateway.mixins import EnterpriseGatewayConfigMixin
|
25 | 25 |
|
| 26 | +from ...metrics import KERNEL_SHUTDOWN_DURATION_SECONDS, KERNEL_START_DURATION_SECONDS |
26 | 27 | from ..processproxies.processproxy import BaseProcessProxyABC, LocalProcessProxy, RemoteProcessProxy
|
27 | 28 | from ..sessions.kernelsessionmanager import KernelSessionManager
|
28 | 29 |
|
@@ -501,7 +502,12 @@ async def start_kernel(self, **kwargs: dict[str, Any] | None):
|
501 | 502 | """
|
502 | 503 | self._get_process_proxy()
|
503 | 504 | self._capture_user_overrides(**kwargs)
|
504 |
| - await super().start_kernel(**kwargs) |
| 505 | + with KERNEL_START_DURATION_SECONDS.time() as timer: |
| 506 | + timer.labels( |
| 507 | + kernel_name=self.kernel_name, |
| 508 | + process_proxy=f'{self.process_proxy.__class__.__module__}.{type(self.process_proxy).__name__}', |
| 509 | + ) |
| 510 | + await super().start_kernel(**kwargs) |
505 | 511 |
|
506 | 512 | def _capture_user_overrides(self, **kwargs: dict[str, Any] | None) -> None:
|
507 | 513 | """
|
@@ -588,6 +594,31 @@ def request_shutdown(self, restart: bool = False) -> None:
|
588 | 594 | if isinstance(self.process_proxy, RemoteProcessProxy):
|
589 | 595 | self.process_proxy.shutdown_listener()
|
590 | 596 |
|
| 597 | + async def shutdown_kernel(self, now: bool = False, restart: bool = False): |
| 598 | + """Attempts to stop the kernel process cleanly. |
| 599 | +
|
| 600 | + This attempts to shutdown the kernels cleanly by: |
| 601 | +
|
| 602 | + 1. Sending it a shutdown message over the control channel. |
| 603 | + 2. If that fails, the kernel is shutdown forcibly by sending it |
| 604 | + a signal. |
| 605 | +
|
| 606 | + Parameters |
| 607 | + ---------- |
| 608 | + now : bool |
| 609 | + Should the kernel be forcible killed *now*. This skips the |
| 610 | + first, nice shutdown attempt. |
| 611 | + restart: bool |
| 612 | + Will this kernel be restarted after it is shutdown. When this |
| 613 | + is True, connection files will not be cleaned up. |
| 614 | + """ |
| 615 | + with KERNEL_SHUTDOWN_DURATION_SECONDS.time() as timer: |
| 616 | + timer.labels( |
| 617 | + kernel_name=self.kernel_name, |
| 618 | + process_proxy=f'{self.process_proxy.__class__.__module__}.{type(self.process_proxy).__name__}', |
| 619 | + ) |
| 620 | + await super().shutdown_kernel(now=now, restart=restart) |
| 621 | + |
591 | 622 | async def restart_kernel(self, now: bool = False, **kwargs: dict[str, Any] | None) -> None:
|
592 | 623 | """
|
593 | 624 | Restarts a kernel with the arguments that were used to launch it.
|
|
0 commit comments