bpy_jupyter.utils
bpy_jupyter.utils
All independent, stateless utilities that ship with this extension.
bpy_jupyter.utils.ipykernel
Utilities making it easy to embed an ipykernel
inside of another Python process.
References
See Also
- Wrapper Kernels: https://ipython.readthedocs.io/en/stable/development/wrapperkernels.html
- Jupyter Lab w/Existing Kernels: https://github.com/jupyterlab/jupyterlab/issues/2044
IPyKernel
pydantic-model
Bases: BaseModel
An embeddable ipykernel
, which wraps ipykernel.kernelapp.IPKernelApp
in a clean, friendly interface.
ATTRIBUTE | DESCRIPTION |
---|---|
path_connection_file |
Path to the connection file to create
TYPE:
|
_lock |
Blocks the use of
TYPE:
|
_kernel_app |
Running embedded
TYPE:
|
Fields:
-
path_connection_file
(Path
) -
_lock
(Lock
) -
_kernel_app
(IPKernelApp | None
)
connection_info
cached
property
connection_info: JupyterKernelConnectionInfo
Parsed kernel connection file for the currently running Jupyter kernel.
is_running
cached
property
is_running: bool
Whether this Jupyter kernel is currently running.
start
start() -> None
Start this Jupyter kernel.
Notes
An asyncio
event loop must be available before kernel requests can be handled, since the embedded IPKernelApp
uses this to await
client requests.
RAISES | DESCRIPTION |
---|---|
ValueError
|
If an |
Source code in bpy_jupyter/utils/ipykernel.py
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 |
|
stop
stop() -> None
Stop this Jupyter kernel.
Notes
Unfortunately, IPKernelApp
doesn't provide any kind of stop()
function.
Therefore, this method involves a LOT of manual hijinks and hacks used in order to cleanly stop and vacuum the running kernel.
RAISES | DESCRIPTION |
---|---|
ValueError
|
If an |
RuntimeErorr
|
If the |
References
traitlets.config.SingletonConfigurable
: https://traitlets.readthedocs.io/en/stable/config-api.html#traitlets.config.SingletonConfigurableZMQStream.flush()
: https://pyzmq.readthedocs.io/en/latest/api/zmq.eventloop.zmqstream.html#zmq.eventloop.zmqstream.ZMQStream.flushzmq.Socket.setsockopt()
: https://pyzmq.readthedocs.io/en/latest/api/zmq.html#zmq.Socket.setsockoptzmq_setsockopt
Options: https://libzmq.readthedocs.io/en/zeromq4-x/zmq_setsockopt.htmlIPKernel
Initialization: https://github.com/ipython/ipykernel/blob/b1283b14419969e36329c1ae957509690126b057/ipykernel/kernelapp.py#L547IPKernelApp.close()
: https://github.com/ipython/ipykernel/blob/b1283b14419969e36329c1ae957509690126b057/ipykernel/kernelapp.py#L393IPKernel.shell_class
Instancing: https://github.com/ipython/ipykernel/blob/b1283b14419969e36329c1ae957509690126b057/ipykernel/ipkernel.py#L125
See Also
- Illustrative
FIXME
for Kernel Stop inipykernel/gui/gtkembed.py
: https://github.com/ipython/ipykernel/blob/b1283b14419969e36329c1ae957509690126b057/ipykernel/gui/gtkembed.py#L65 ZMQ_TCP_KEEPALIVE
Workaround for Lingering FDs: https://github.com/zeromq/libzmq/issues/1453man 7 tcp
on Linux: https://man7.org/linux/man-pages/man7/tcp.7.html
Source code in bpy_jupyter/utils/ipykernel.py
186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 |
|
JupyterKernelConnectionInfo
pydantic-model
Bases: BaseModel
Structure that completely defines how to communicate with a running Jupyter kernel.
Notes
This is directly analogous, and is in fact parsed directly from, the conventional "connection file".
ATTRIBUTE | DESCRIPTION |
---|---|
kernel_name |
Name of the kernel.
TYPE:
|
ip |
The IP address that the kernel binds ports to.
TYPE:
|
shell_port |
Port of the kernel shell socket.
TYPE:
|
iopub_port |
Port of the kernel iopub socket.
TYPE:
|
stdin_port |
Port of the kernel stdin socket.
TYPE:
|
control_port |
Port of the kernel control socket.
TYPE:
|
hb_port |
Port of the kernel heartbeat socket.
TYPE:
|
key |
Secret key that should be used to authenticate with the kernel.
TYPE:
|
transport |
Protocol that should be used to communicate with the kernel.
TYPE:
|
signature_scheme |
Cipher suite that should be used to validate message authenticity.
TYPE:
|
Fields:
-
ip
(IPv4Address | IPv4Address
) -
shell_port
(int
) -
iopub_port
(int
) -
stdin_port
(int
) -
control_port
(int
) -
hb_port
(int
) -
key
(SecretStr
) -
transport
(Literal['tcp']
) -
signature_scheme
(Literal['hmac-sha256']
) -
kernel_name
(str
)
json_str
cached
property
json_str: str
The JSON string corresponding to this model.
Notes
self.key
is not directly included; rather a placeholder of ****
's are included instead.
If including the real self.key
is important, please use self.json_str_with_key
.
json_str_with_key
cached
property
json_str_with_key: str
The JSON string corresponding to this model, including the true value of self.key
.
Notes
Use of this property should be minimized, as the exposure of self.key
in ex. logs may compromise the security of the kernel.
from_path_connection_file
classmethod
from_path_connection_file(
path_connection_file: Path,
) -> Self
Construct from a Jupyter kernel connection file, including self.key
.
Source code in bpy_jupyter/utils/ipykernel.py
102 103 104 105 106 |
|