@@ -141,9 +141,18 @@ def create_kernel(
141
141
:param timeout: Timeout for the kernel creation request.
142
142
:return: Kernel id of the created kernel
143
143
"""
144
- data = {"path" : cwd , "kernel" : {"name" : "python3" }, "type" : "notebook" , "name" : str (uuid .uuid4 ())}
145
- if kernel_name :
146
- data ["kernel" ]['name' ] = kernel_name
144
+ kernel_name = kernel_name or "python3"
145
+ response = requests .post (
146
+ f"{ self ._sandbox .get_protocol ()} ://{ self ._sandbox .get_hostname (8888 )} /api/kernels" ,
147
+ json = {"name" : kernel_name , "path" : cwd },
148
+ timeout = timeout ,
149
+ )
150
+ if not response .ok :
151
+ raise KernelException (f"Failed to create kernel: { response .text } " )
152
+
153
+ kernel_data = response .json ()
154
+ kernel_id = kernel_data ["id" ]
155
+ data = {"path" : str (uuid .uuid4 ()), "kernel" : {"name" : kernel_name , "id" : kernel_id }, "type" : "notebook" , "name" : str (uuid .uuid4 ())}
147
156
logger .debug (f"Creating kernel with data: { data } " )
148
157
149
158
response = requests .post (
@@ -155,8 +164,17 @@ def create_kernel(
155
164
raise KernelException (f"Failed to create kernel: { response .text } " )
156
165
157
166
session_data = response .json ()
158
- kernel_id = session_data ["kernel" ]["id" ]
159
167
session_id = session_data ["id" ]
168
+ kernel_id = session_data ["kernel" ]["id" ]
169
+
170
+ response = requests .patch (
171
+ f"{ self ._sandbox .get_protocol ()} ://{ self ._sandbox .get_hostname (8888 )} /api/sessions/{ session_id } " ,
172
+ json = {"path" : cwd },
173
+ timeout = timeout ,
174
+ )
175
+ if not response .ok :
176
+ raise KernelException (f"Failed to create kernel: { response .text } " )
177
+
160
178
logger .debug (f"Created kernel { kernel_id } " )
161
179
162
180
threading .Thread (
0 commit comments