kernel
Classes:
-
KernelInterrupt–Raised to interrupt the kernel.
-
Kernel–The class containing the handler methods to implement a Jupyter Kernel.
KernelInterrupt
¶
Bases: InterruptedError
Raised to interrupt the kernel.
Source code in src/async_kernel/common.py
44 45 | |
Kernel
¶
Bases: HasInterface[T_interface_co], LoggingConfigurable, AsyncContextManagerMixin, Generic[T_interface_co, T_shell_co]
The class containing the handler methods to implement a Jupyter Kernel.
- Reference Reference Highlights
Methods:
-
__asynccontextmanager__–The kernel runs in this context.
-
do_interrupt–Interrupt/cancel non-silent active execute requests.
-
apply_patches–Apply patches returning a callable to reverse the patches.
-
displayhook–The global patch for sys.displayhook responsible for python display callbacks.
-
handle_request–Schedule handling of the job (msg) with a handler running in a Task managed by a Caller.
-
get_shell–Get a shell by
subshell_id. -
create_subshell–Create a subshell.
-
kernel_info_request–Handle an kernel info request.
-
comm_info_request–Handle an comm info request.
-
execute_request–Handle an execute request.
-
complete_request–Handle an completion request.
-
is_complete_request–Handle an is_complete request.
-
inspect_request–Handle an inspect request.
-
history_request–Handle an history request.
-
comm_open–Handle an comm open request.
-
comm_msg–Handle an comm msg request.
-
comm_close–Handle an comm close request.
-
interrupt_request–Handle an interrupt request.
-
shutdown_request–Handle an shutdown request.
-
debug_request–Handle an debug request.
-
create_subshell_request–Handle an create subshell request.
-
delete_subshell_request–Handle an delete subshell request.
-
list_subshell_request–Handle an list subshell request.
-
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, also used for builtin 'input'.
Attributes:
-
help_links–A list of links provided kernel info request.
-
supported_features–A list of features supported by the kernel.
-
handle_in_shell_thread–A list of
MsgTypethat are always handled in the shell's thread (typically the MainThread). -
handle_in_thread–A mapping of
MsgTypeto the name of a separate caller (thread) in which to run the handler. -
callers(Fixed[Self, dict]) –A shortcut to the callers dict on the parent.
-
caller(Fixed[Self, Caller]) –The caller for the shell thread.
-
debugger–The debugger for handling debug requests.
-
comm_manager(Fixed[Self, CommManager]) –Creates async_kernel.comm.Comm instances and maintains a mapping to
comm_idtoComminstances. -
stopped–A pending that is set once the kernel has stopped.
-
active_execute_requests(Fixed[Self, set[Pending[Any]]]) –A set of active execute requests that gets updated by the shell.
-
kernel_info(dict[str, Any]) –Info provided to a kernel info request.
-
shell(T_shell_co) –The shell given the current context.
Source code in src/async_kernel/kernel.py
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 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 | |
help_links
class-attribute
instance-attribute
¶
A list of links provided kernel info request.
supported_features
class-attribute
instance-attribute
¶
A list of features supported by the kernel.
handle_in_shell_thread
class-attribute
instance-attribute
¶
handle_in_shell_thread = traitlets.List(
traitlets.UseEnum(MsgType), [MsgType.comm_msg, MsgType.comm_open, MsgType.comm_close]
).tag(config=True)
A list of MsgType that are always handled in the shell's thread (typically the MainThread).
handle_in_thread
class-attribute
instance-attribute
¶
handle_in_thread = traitlets.Dict(
key_trait=traitlets.UseEnum(MsgType), value_trait=traitlets.Unicode()
)
A mapping of MsgType to the name of a separate caller (thread) in which to run the handler.
callers
class-attribute
instance-attribute
¶
A shortcut to the callers dict on the parent.
caller
class-attribute
instance-attribute
¶
The caller for the shell thread.
debugger
class-attribute
instance-attribute
¶
The debugger for handling debug requests.
comm_manager
class-attribute
instance-attribute
¶
Creates async_kernel.comm.Comm instances and maintains a mapping to comm_id to Comm instances.
stopped
class-attribute
instance-attribute
¶
stopped = Fixed(ProtectedPending)
A pending that is set once the kernel has stopped.
active_execute_requests
class-attribute
instance-attribute
¶
A set of active execute requests that gets updated by the shell.
shell
property
¶
shell: T_shell_co
The shell given the current context.
Notes
- The
subshell_idof the main shell isNone.
__asynccontextmanager__
async
¶
__asynccontextmanager__() -> AsyncGenerator[Self]
The kernel runs in this context.
Notes
- Entered by the interface (parent).
- Overload as required.
Source code in src/async_kernel/kernel.py
181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 | |
do_interrupt
async
¶
do_interrupt() -> None
Interrupt/cancel non-silent active execute requests.
Source code in src/async_kernel/kernel.py
218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 | |
apply_patches
¶
apply_patches() -> Callable[[], None]
Apply patches returning a callable to reverse the patches.
Source code in src/async_kernel/kernel.py
253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 | |
displayhook
¶
displayhook(result: Any)
The global patch for sys.displayhook responsible for python display callbacks.
-
Reference
ipshell
IPShelldisplayhook
Source code in src/async_kernel/kernel.py
269 270 271 | |
handle_request
¶
Schedule handling of the job (msg) with a handler running in a Task managed by a Caller.
Each msg_type runs in a separate task, possibly in a separate thread and event loop.
Typically, jobs are queued for execution by either the 'shell' or 'control' caller using
queue_call.
'execute_request' messages can also specify alternate run modes: - task: Run the execute request as a task. - thread: Run the execute request in a worker thread.
The alternate run mode can be specified in a few ways:
- as a comment on the first line of the code block `# task` or `# thread`.
- As a tag `thread` or `task`
Parameters:
Source code in src/async_kernel/kernel.py
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 | |
get_shell
¶
get_shell(subshell_id: str | NoValue | None = NoValue) -> T_shell_co
Get a shell by subshell_id.
Parameters:
Source code in src/async_kernel/kernel.py
407 408 409 410 411 412 413 414 415 | |
create_subshell
¶
Create a subshell.
Use shell.stop(force=True) to stop a
protected subshell when it is no longer required.
Parameters:
Tip
await shell.readyto ensure the shell is 'ready'.
Source code in src/async_kernel/kernel.py
417 418 419 420 421 422 423 424 425 426 427 428 429 | |
kernel_info_request
async
¶
Handle an kernel info request.
Source code in src/async_kernel/kernel.py
431 432 433 | |
comm_info_request
async
¶
Handle an comm info request.
Source code in src/async_kernel/kernel.py
435 436 437 438 439 440 441 442 443 444 | |
execute_request
async
¶
execute_request(job: Job[ExecuteContent]) -> Content
Handle an execute request.
Source code in src/async_kernel/kernel.py
446 447 448 449 450 451 452 453 | |
complete_request
async
¶
Handle an completion request.
Source code in src/async_kernel/kernel.py
455 456 457 458 459 | |
is_complete_request
async
¶
Handle an is_complete request.
Source code in src/async_kernel/kernel.py
461 462 463 | |
inspect_request
async
¶
Handle an inspect request.
Source code in src/async_kernel/kernel.py
465 466 467 468 469 470 471 472 | |
history_request
async
¶
Handle an history request.
Source code in src/async_kernel/kernel.py
474 475 476 | |
comm_open
async
¶
Handle an comm open request.
Source code in src/async_kernel/kernel.py
478 479 480 | |
comm_msg
async
¶
Handle an comm msg request.
Source code in src/async_kernel/kernel.py
482 483 484 | |
comm_close
async
¶
Handle an comm close request.
Source code in src/async_kernel/kernel.py
486 487 488 | |
interrupt_request
async
¶
Handle an interrupt request.
Source code in src/async_kernel/kernel.py
490 491 492 493 | |
shutdown_request
async
¶
Handle an shutdown request.
Source code in src/async_kernel/kernel.py
495 496 497 498 499 500 501 502 503 504 | |
debug_request
async
¶
Handle an debug request.
Source code in src/async_kernel/kernel.py
506 507 508 | |
create_subshell_request
async
¶
Handle an create subshell request.
Source code in src/async_kernel/kernel.py
510 511 512 513 514 | |
delete_subshell_request
async
¶
Handle an delete subshell request.
Source code in src/async_kernel/kernel.py
516 517 518 519 520 | |
list_subshell_request
async
¶
Handle an list subshell request.
Source code in src/async_kernel/kernel.py
522 523 524 | |
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
526 527 528 529 530 531 532 533 534 535 536 | |
do_complete
async
¶
Matches signature of ipykernel.kernelbase.Kernel.do_complete.
Source code in src/async_kernel/kernel.py
538 539 540 | |
do_inspect
async
¶
do_inspect(
code: str, cursor_pos: int = 0, detail_level: Literal[0, 1] = 0, omit_sections=()
) -> Content
Matches signature of ipykernel.kernelbase.Kernel.do_inspect.
Source code in src/async_kernel/kernel.py
542 543 544 545 546 | |
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
548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 | |
do_execute
async
¶
do_execute(
code: str,
silent: bool = True,
store_history: bool = True,
user_expressions: dict[str, str] | None = None,
allow_stdin: bool = False,
*,
cell_meta: dict[str, Any] | None = None,
cell_id: str | None = None,
**_ignored,
) -> Content
Matches signature of ipykernel.kernelbase.Kernel.do_execute.
Source code in src/async_kernel/kernel.py
570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 | |
getpass
¶
getpass(prompt='', stream=None) -> str
Matches signature of ipykernel.kernelbase.Kernel.getpass.
Source code in src/async_kernel/kernel.py
593 594 595 596 597 598 599 600 601 602 | |
raw_input
¶
raw_input(prompt='') -> str
Matches signature of ipykernel.kernelbase.Kernel.raw_input, also used for builtin 'input'.
Source code in src/async_kernel/kernel.py
604 605 606 607 608 609 610 611 612 613 | |