kernel
Classes:
-
KernelInterrupt–Raised to interrupt the kernel.
-
Kernel–A Jupyter kernel providing an IPython InteractiveShell.
KernelInterrupt
¶
Bases: InterruptedError
Raised to interrupt the kernel.
Source code in src/async_kernel/common.py
46 47 | |
Kernel
¶
Bases: HasTraits
A Jupyter kernel providing an IPython InteractiveShell.
Starting the kernel:
=== "From the shell"
``` shell
async-kernel --kernel-name=async -f .
```
=== "Blocking"
```python
import async_kernel.interface
settings = {} # Dotted name key/value pairs
async_kernel.interface.start_kernel_zmq_interface(settings)
```
=== "Async"
```python
settings = {} # Dotted name key/value pairs
async with Kernel(settings).interface:
...
```
Warning
Starting the kernel outside the main thread has the following implicatations: - Execute requests are run in the thread where the kernel is started. - The signal based kernel interrupt is not possible.
Methods:
-
load_settings–Load settings into the kernel.
-
load_connection_info–Load connection info from a dict containing connection info.
-
do_shutdown–Matches signature of ipykernel.kernelbase.Kernel.do_shutdown.
-
kernel_info_request–Handle a kernel info request.
-
comm_info_request–Handle a comm info request.
-
execute_request–Handle a execute request.
-
complete_request–Handle a completion request.
-
is_complete_request–Handle a is_complete request.
-
inspect_request–Handle a inspect request.
-
history_request–Handle a history request.
-
comm_open–Handle a comm open request.
-
comm_msg–Handle a comm msg request.
-
comm_close–Handle a comm close request.
-
interrupt_request–Handle an interrupt request.
-
shutdown_request–Handle a shutdown request.
-
debug_request–Handle a debug request.
-
create_subshell_request–Handle a create subshell request.
-
delete_subshell_request–Handle a delete subshell request.
-
list_subshell_request–Handle a list subshell request.
-
get_connection_info–Return the connection info as a dict.
-
get_parent–A convenience method to access the 'message' in the current context if there is one.
-
do_complete–Matches signature of ipykernel.kernelbase.Kernel.do_complete.
-
do_inspect–Matches signature of ipykernel.kernelbase.Kernel.do_inspect.
-
do_history–Matches signature of ipykernel.kernelbase.Kernel.do_history.
-
do_execute–Matches signature of ipykernel.kernelbase.Kernel.do_execute.
-
getpass–Matches signature of ipykernel.kernelbase.Kernel.getpass.
-
raw_input–Matches signature of ipykernel.kernelbase.Kernel.raw_input.
Attributes:
-
interface(Instance[BaseKernelInterface]) –The abstraction to interface with the kernel.
-
subshell_manager–Dedicated to management of sub shells.
-
quiet–Only send stdout/stderr to output stream.
-
print_kernel_messages–When enabled the kernel will print startup, shutdown and terminal errors.
-
connection_file(TraitType[Path, Path | str]) –JSON file in which to store connection info.
-
kernel_name–The kernels name - if it contains 'trio' a trio backend will be used instead of an asyncio backend.
-
help_links–A list of links provided kernel info request.
-
supported_features–A list of features supported by the kernel.
-
banner–The banner to display in a console.
-
log–The logging adapter.
-
main_shell(Fixed[Self, AsyncInteractiveShell]) –The interactive shell.
-
comm_manager–Creates async_kernel.comm.Comm instances and maintains a mapping to
comm_idtoComminstances. -
event_started–An event that occurs when the kernel is started.
-
event_stopped–An event that occurs when the kernel is stopped.
-
kernel_info(dict[str, Any]) –Info provided to a kernel info request.
-
settings(dict[str, Any]) –Settings that have been set to customise the behaviour of the kernel.
-
shell(AsyncInteractiveShell | AsyncInteractiveSubshell) –The shell given the current context.
-
caller(Caller) –The caller for the shell channel.
Source code in src/async_kernel/kernel.py
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 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 185 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 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 | |
interface
class-attribute
instance-attribute
¶
interface: Instance[BaseKernelInterface] = Instance(BaseKernelInterface)
The abstraction to interface with the kernel.
subshell_manager
class-attribute
instance-attribute
¶
subshell_manager = SubshellManager
Dedicated to management of sub shells.
quiet
class-attribute
instance-attribute
¶
quiet = Bool(True)
Only send stdout/stderr to output stream.
print_kernel_messages
class-attribute
instance-attribute
¶
print_kernel_messages = Bool(True)
When enabled the kernel will print startup, shutdown and terminal errors.
connection_file
class-attribute
instance-attribute
¶
JSON file in which to store connection info.
"kernel-<pid>.json"
This file will contain the IP, ports, and authentication key needed to connect clients to this kernel. By default, this file will be created in the security dir of the current profile, but can be specified by absolute path.
kernel_name
class-attribute
instance-attribute
¶
kernel_name = CUnicode()
The kernels name - if it contains 'trio' a trio backend will be used instead of an asyncio backend.
help_links
class-attribute
instance-attribute
¶
help_links = List(trait=Dict())
A list of links provided kernel info request.
supported_features
class-attribute
instance-attribute
¶
supported_features = List(Unicode())
A list of features supported by the kernel.
main_shell
class-attribute
instance-attribute
¶
main_shell: Fixed[Self, AsyncInteractiveShell] = Fixed(AsyncInteractiveShell)
The interactive shell.
comm_manager
class-attribute
instance-attribute
¶
comm_manager = Fixed(CommManager)
Creates async_kernel.comm.Comm instances and maintains a mapping to comm_id to Comm instances.
event_started
class-attribute
instance-attribute
¶
An event that occurs when the kernel is started.
event_stopped
class-attribute
instance-attribute
¶
An event that occurs when the kernel is stopped.
settings
property
¶
Settings that have been set to customise the behaviour of the kernel.
shell
property
¶
The shell given the current context.
Notes
- The
subshell_idof the main shell isNone.
load_settings
¶
Load settings into the kernel.
Permitted until the kernel async context has been entered.
Parameters:
Source code in src/async_kernel/kernel.py
261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 | |
load_connection_info
¶
Load connection info from a dict containing connection info.
Typically this data comes from a connection file and is called by load_connection_file.
Parameters:
-
(info¶dict[str, Any]) –Dictionary containing connection_info. See the connection_file spec for details.
Source code in src/async_kernel/kernel.py
280 281 282 283 284 285 286 287 288 289 290 | |
do_shutdown
async
¶
do_shutdown(restart: bool) -> None
Matches signature of ipykernel.kernelbase.Kernel.do_shutdown.
Source code in src/async_kernel/kernel.py
292 293 294 295 296 297 298 299 300 301 302 303 304 | |
kernel_info_request
async
¶
Handle a kernel info request.
-
Reference
typing
MsgTypekernel_info_request
Source code in src/async_kernel/kernel.py
306 307 308 | |
comm_info_request
async
¶
Handle a comm info request.
-
Reference
typing
MsgTypecomm_info_request
Source code in src/async_kernel/kernel.py
310 311 312 313 314 315 316 317 318 319 | |
execute_request
async
¶
execute_request(job: Job[ExecuteContent]) -> Content
Handle a execute request.
-
Reference
typing
MsgTypeexecute_request
Source code in src/async_kernel/kernel.py
321 322 323 324 325 326 327 | |
complete_request
async
¶
Handle a completion request.
Source code in src/async_kernel/kernel.py
329 330 331 332 333 | |
is_complete_request
async
¶
Handle a is_complete request.
-
Reference
typing
MsgTypeis_complete_request
Source code in src/async_kernel/kernel.py
335 336 337 | |
inspect_request
async
¶
Handle a inspect request.
Source code in src/async_kernel/kernel.py
339 340 341 342 343 344 345 346 | |
history_request
async
¶
Handle a history request.
Source code in src/async_kernel/kernel.py
348 349 350 | |
comm_open
async
¶
Handle a comm open request.
Source code in src/async_kernel/kernel.py
352 353 354 | |
comm_msg
async
¶
Handle a comm msg request.
Source code in src/async_kernel/kernel.py
356 357 358 | |
comm_close
async
¶
Handle a comm close request.
-
Reference
typing
MsgTypecomm_close
Source code in src/async_kernel/kernel.py
360 361 362 | |
interrupt_request
async
¶
Handle an interrupt request.
-
Reference
typing
MsgTypeinterrupt_request
Source code in src/async_kernel/kernel.py
364 365 366 367 | |
shutdown_request
async
¶
Handle a shutdown request.
Source code in src/async_kernel/kernel.py
369 370 371 372 373 | |
debug_request
async
¶
Handle a debug request.
Source code in src/async_kernel/kernel.py
375 376 377 | |
create_subshell_request
async
¶
Handle a create subshell request.
-
Reference
typing
MsgTypecreate_subshell_request
Source code in src/async_kernel/kernel.py
379 380 381 382 | |
delete_subshell_request
async
¶
Handle a delete subshell request.
-
Reference
typing
MsgTypedelete_subshell_request
Source code in src/async_kernel/kernel.py
384 385 386 387 | |
list_subshell_request
async
¶
Handle a list subshell request.
Source code in src/async_kernel/kernel.py
389 390 391 | |
get_connection_info
¶
Return the connection info as a dict.
Source code in src/async_kernel/kernel.py
393 394 395 | |
get_parent
¶
A convenience method to access the 'message' in the current context if there is one.
'parent' is the parameter name used by Session.send to provide context when sending a reply.
See also
- ipywidgets.Output:
Uses
get_ipython().kernel.get_parent()to obtain themsg_idwhich is used to 'capture' output when its context has been acquired.
Source code in src/async_kernel/kernel.py
397 398 399 400 401 402 403 404 405 406 407 408 | |
do_complete
async
¶
Matches signature of ipykernel.kernelbase.Kernel.do_complete.
Source code in src/async_kernel/kernel.py
410 411 412 | |
do_inspect
async
¶
Matches signature of ipykernel.kernelbase.Kernel.do_inspect.
Source code in src/async_kernel/kernel.py
414 415 416 | |
do_history
async
¶
do_history(
hist_access_type,
output,
raw,
session=None,
start=None,
stop=None,
n=None,
pattern=None,
unique=False,
) -> Content
Matches signature of ipykernel.kernelbase.Kernel.do_history.
Source code in src/async_kernel/kernel.py
418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 | |
do_execute
async
¶
do_execute(
code: str,
silent: bool,
store_history: bool = True,
user_expressions: dict | None = None,
allow_stdin=False,
*,
cell_id: str | None = None,
**_ignored,
) -> Content
Matches signature of ipykernel.kernelbase.Kernel.do_execute.
Source code in src/async_kernel/kernel.py
440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 | |
getpass
¶
getpass(prompt='', stream=None) -> str
Matches signature of ipykernel.kernelbase.Kernel.getpass.
Source code in src/async_kernel/kernel.py
476 477 478 | |
raw_input
¶
raw_input(prompt='') -> str
Matches signature of ipykernel.kernelbase.Kernel.raw_input.
Source code in src/async_kernel/kernel.py
480 481 482 | |