|
7 | 7 | # Distributed under the terms of the Modified BSD License.
|
8 | 8 | import asyncio
|
9 | 9 | import os
|
| 10 | +import warnings |
10 | 11 | from collections import defaultdict
|
11 | 12 | from datetime import datetime, timedelta
|
12 | 13 | from functools import partial
|
13 | 14 |
|
| 15 | +from jupyter_client.ioloop.manager import AsyncIOLoopKernelManager |
14 | 16 | from jupyter_client.multikernelmanager import (
|
15 | 17 | AsyncMultiKernelManager,
|
16 | 18 | MultiKernelManager,
|
|
36 | 38 |
|
37 | 39 | from jupyter_server._tz import isoformat, utcnow
|
38 | 40 | from jupyter_server.prometheus.metrics import KERNEL_CURRENTLY_RUNNING_TOTAL
|
39 |
| -from jupyter_server.utils import ensure_async, to_os_path |
| 41 | +from jupyter_server.utils import ensure_async, import_item, to_os_path |
40 | 42 |
|
41 | 43 |
|
42 | 44 | class MappingKernelManager(MultiKernelManager):
|
@@ -656,10 +658,34 @@ async def cull_kernel_if_idle(self, kernel_id):
|
656 | 658 | class AsyncMappingKernelManager(MappingKernelManager, AsyncMultiKernelManager):
|
657 | 659 | @default("kernel_manager_class")
|
658 | 660 | def _default_kernel_manager_class(self):
|
659 |
| - return "jupyter_client.ioloop.AsyncIOLoopKernelManager" |
| 661 | + return "jupyter_server.services.kernels.kernelmanager.ServerKernelManager" |
| 662 | + |
| 663 | + @validate("kernel_manager_class") |
| 664 | + def _validate_kernel_manager_class(self, proposal): |
| 665 | + km_class_value = proposal.value |
| 666 | + km_class = import_item(km_class_value) |
| 667 | + if not issubclass(km_class, ServerKernelManager): |
| 668 | + warnings.warn( |
| 669 | + f"KernelManager class '{km_class}' is not a subclass of 'ServerKernelManager'. Custom " |
| 670 | + "KernelManager classes should derive from 'ServerKernelManager' beginning with jupyter-server 2.0 " |
| 671 | + "or risk missing functionality. Continuing...", |
| 672 | + FutureWarning, |
| 673 | + stacklevel=3, |
| 674 | + ) |
| 675 | + return km_class_value |
660 | 676 |
|
661 | 677 | def __init__(self, **kwargs):
|
662 | 678 | self.pinned_superclass = MultiKernelManager
|
663 | 679 | self._pending_kernel_tasks = {}
|
664 | 680 | self.pinned_superclass.__init__(self, **kwargs)
|
665 | 681 | self.last_kernel_activity = utcnow()
|
| 682 | + |
| 683 | + |
| 684 | +class ServerKernelManager(AsyncIOLoopKernelManager): |
| 685 | + |
| 686 | + # Define activity-related attributes: |
| 687 | + execution_state = Unicode( |
| 688 | + None, allow_none=True, help="The current execution state of the kernel" |
| 689 | + ) |
| 690 | + reason = Unicode("", help="The reason for the last failure against the kernel") |
| 691 | + last_activity = Instance(datetime, help="The last activity on the kernel") |
0 commit comments