1
1
import os
2
+ import uuid
2
3
import json
3
4
import asyncio
4
5
import signal
@@ -105,12 +106,21 @@ async def start(self) -> None:
105
106
self .kernelspec_path , self .connection_file_path , self .capture_kernel_output
106
107
)
107
108
assert self .connection_cfg is not None
108
- self .shell_channel = connect_channel ("shell" , self .connection_cfg )
109
- self .control_channel = connect_channel ("control" , self .connection_cfg )
109
+ identity = uuid .uuid4 ().hex .encode ("ascii" )
110
+ self .shell_channel = connect_channel (
111
+ "shell" , self .connection_cfg , identity = identity
112
+ )
113
+ self .stdin_channel = connect_channel (
114
+ "stdin" , self .connection_cfg , identity = identity
115
+ )
116
+ self .control_channel = connect_channel (
117
+ "control" , self .connection_cfg , identity = identity
118
+ )
110
119
self .iopub_channel = connect_channel ("iopub" , self .connection_cfg )
111
120
await self ._wait_for_ready ()
112
121
self .channel_tasks += [
113
122
asyncio .create_task (self .listen ("shell" )),
123
+ asyncio .create_task (self .listen ("stdin" )),
114
124
asyncio .create_task (self .listen ("control" )),
115
125
asyncio .create_task (self .listen ("iopub" )),
116
126
]
@@ -154,6 +164,8 @@ async def listen(self, channel_name: str):
154
164
channel = self .control_channel
155
165
elif channel_name == "iopub" :
156
166
channel = self .iopub_channel
167
+ elif channel_name == "stdin" :
168
+ channel = self .stdin_channel
157
169
158
170
while True :
159
171
parts = await get_zmq_parts (channel )
@@ -196,6 +208,8 @@ async def send_to_zmq(self, websocket):
196
208
send_message (msg , self .shell_channel , self .key )
197
209
elif channel == "control" :
198
210
send_message (msg , self .control_channel , self .key )
211
+ elif channel == "stdin" :
212
+ send_message (msg , self .stdin_channel , self .key )
199
213
elif websocket .accepted_subprotocol == "v1.kernel.websocket.jupyter.org" :
200
214
while True :
201
215
msg = await websocket .websocket .receive_bytes ()
@@ -213,6 +227,8 @@ async def send_to_zmq(self, websocket):
213
227
send_raw_message (parts , self .shell_channel , self .key )
214
228
elif channel == "control" :
215
229
send_raw_message (parts , self .control_channel , self .key )
230
+ elif channel == "stdin" :
231
+ send_raw_message (parts , self .stdin_channel , self .key )
216
232
217
233
async def send_to_ws (self , websocket , parts , parent_header , channel_name ):
218
234
if not websocket .accepted_subprotocol :
0 commit comments