Skip to content

Commit 5f8d2f3

Browse files
committed
more updates for unit tests
1 parent 9cec9e8 commit 5f8d2f3

File tree

4 files changed

+29
-9
lines changed

4 files changed

+29
-9
lines changed

jupyter_server/services/kernels/connection/abc.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from abc import ABC, abstractmethod
2-
from typing import Callable
2+
from typing import Any
33

44

55
class KernelWebsocketConnectionABC(ABC):
@@ -10,7 +10,7 @@ class KernelWebsocketConnectionABC(ABC):
1010
interface.
1111
"""
1212

13-
write_message: Callable
13+
websocket_handler: Any
1414

1515
@abstractmethod
1616
async def connect(self):

jupyter_server/services/kernels/connection/base.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
import sys
44

55
from jupyter_client.session import Session
6-
from traitlets import Callable, Float, Instance, default
6+
from tornado.websocket import WebSocketHandler
7+
from traitlets import Float, Instance, default
78
from traitlets.config import LoggingConfigurable
89

910
try:
@@ -135,7 +136,7 @@ def _default_kernel_info_timeout(self):
135136
def _default_session(self):
136137
return Session(config=self.config)
137138

138-
write_message = Callable()
139+
websocket_handler = Instance(WebSocketHandler)
139140

140141
async def connect(self):
141142
raise NotImplementedError()

jupyter_server/services/kernels/connection/channels.py

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,24 @@ class ZMQChannelsWebsocketConnection(BaseKernelWebsocketConnection):
7979
),
8080
)
8181

82+
kernel_ws_protocol = Unicode(
83+
None,
84+
allow_none=True,
85+
config=True,
86+
help=_i18n(
87+
"Preferred kernel message protocol over websocket to use (default: None). "
88+
"If an empty string is passed, select the legacy protocol. If None, "
89+
"the selected protocol will depend on what the front-end supports "
90+
"(usually the most recent protocol supported by the back-end and the "
91+
"front-end)."
92+
),
93+
)
94+
95+
@property
96+
def write_message(self):
97+
"""Alias to the websocket handler's write_message method."""
98+
return self.websocket_handler.write_message
99+
82100
# class-level registry of open sessions
83101
# allows checking for conflict on session-id,
84102
# which is used as a zmq identity and must be unique.
@@ -117,13 +135,14 @@ def _default_close_future(self):
117135
@classmethod
118136
async def close_all(cls):
119137
"""Tornado does not provide a way to close open sockets, so add one."""
120-
for socket in list(cls._open_sockets):
121-
await socket.close()
138+
for connection in list(cls._open_sockets):
139+
connection.disconnect()
140+
await _ensure_future(connection._close_future)
122141

123142
@property
124143
def subprotocol(self):
125144
try:
126-
protocol = self.selected_subprotocol
145+
protocol = self.websocket_handler.selected_subprotocol
127146
except Exception:
128147
protocol = None
129148
return protocol
@@ -520,7 +539,7 @@ def _on_zmq_reply(self, stream, msg_list):
520539
self.close()
521540
return
522541
channel = getattr(stream, "channel", None)
523-
if self.selected_subprotocol == "v1.kernel.websocket.jupyter.org":
542+
if self.subprotocol == "v1.kernel.websocket.jupyter.org":
524543
bin_msg = serialize_msg_to_ws_v1(msg_list, channel)
525544
self.write_message(bin_msg, binary=True)
526545
else:

jupyter_server/services/kernels/websocket.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ async def pre_get(self):
179179
kernel = self.kernel_manager.get_kernel(self.kernel_id)
180180
self.connection = self.kernel_websocket_connection_class(
181181
parent=kernel,
182-
write_message=self.write_message,
182+
websocket_handler=self,
183183
)
184184

185185
if self.get_argument("session_id", None):

0 commit comments

Comments
 (0)