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
45 46 | |
Kernel
¶
Bases: HasInterface[T_interface_co], LoggingConfigurable, Generic[T_interface_co, T_shell_co]
The class containing the handler methods to implement a Jupyter Kernel.
- Reference Reference Highlights
Methods:
-
running–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.
-
message_handler–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.
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–Creates async_kernel.comm.Comm instances and maintains a mapping to
comm_idtoComminstances. -
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
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 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 | |
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
¶
comm_manager = Fixed(CommManager)
Creates async_kernel.comm.Comm instances and maintains a mapping to comm_id to Comm instances.
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.
running
async
¶
running() -> AsyncGenerator[None]
The kernel runs in this context.
Notes
- Entered by the interface (parent).
- Overload as required.
Source code in src/async_kernel/kernel.py
251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 | |
do_interrupt
async
¶
do_interrupt() -> None
Interrupt/cancel non-silent active execute requests.
Source code in src/async_kernel/kernel.py
287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 | |
apply_patches
¶
apply_patches() -> Callable[[], None]
Apply patches returning a callable to reverse the patches.
Source code in src/async_kernel/kernel.py
324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 | |
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
343 344 345 | |
message_handler
¶
message_handler(
job: Job,
send_reply: Callable[[Job, dict], CoroutineType[Any, Any, None]],
iopub_send: Callable,
) -> None
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:
-
(job¶Job) –A dict with the msg and supporting details.
-
(send_reply¶Callable[[Job, dict], CoroutineType[Any, Any, None]]) –The function for the handler to use to send the reply to the message.
Source code in src/async_kernel/kernel.py
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 | |
get_shell
¶
get_shell(subshell_id: str | None | NoValue = NoValue) -> T_shell_co
Get a shell by subshell_id.
Parameters:
Source code in src/async_kernel/kernel.py
478 479 480 481 482 483 484 485 486 487 | |
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.ready to ensure the shell is 'ready'.
Source code in src/async_kernel/kernel.py
489 490 491 492 493 494 495 496 497 498 499 500 501 502 | |
kernel_info_request
async
¶
Handle an kernel info request.
Source code in src/async_kernel/kernel.py
504 505 506 | |
comm_info_request
async
¶
Handle an comm info request.
-
Reference
typing
MsgTypecomm_info_request
Source code in src/async_kernel/kernel.py
508 509 510 511 512 513 514 515 516 517 | |
execute_request
async
¶
execute_request(job: Job[ExecuteContent]) -> Content
Handle an execute request.
-
Reference
typing
MsgTypeexecute_request
Source code in src/async_kernel/kernel.py
519 520 521 522 523 524 525 526 | |
complete_request
async
¶
Handle an completion request.
-
Reference
typing
MsgTypecomplete_request
Source code in src/async_kernel/kernel.py
528 529 530 531 532 | |
is_complete_request
async
¶
Handle an is_complete request.
Source code in src/async_kernel/kernel.py
534 535 536 | |
inspect_request
async
¶
Handle an inspect request.
Source code in src/async_kernel/kernel.py
538 539 540 541 542 543 544 545 | |
history_request
async
¶
Handle an history request.
Source code in src/async_kernel/kernel.py
547 548 549 | |
comm_open
async
¶
Handle an comm open request.
Source code in src/async_kernel/kernel.py
551 552 553 | |
comm_msg
async
¶
Handle an comm msg request.
Source code in src/async_kernel/kernel.py
555 556 557 | |
comm_close
async
¶
Handle an comm close request.
Source code in src/async_kernel/kernel.py
559 560 561 | |
interrupt_request
async
¶
Handle an interrupt request.
Source code in src/async_kernel/kernel.py
563 564 565 566 | |
shutdown_request
async
¶
Handle an shutdown request.
Source code in src/async_kernel/kernel.py
568 569 570 571 572 | |
debug_request
async
¶
Handle an debug request.
-
Reference
typing
MsgTypelist_subshell_request
Source code in src/async_kernel/kernel.py
574 575 576 | |
create_subshell_request
async
¶
Handle an create subshell request.
-
Reference
typing
MsgTypecreate_subshell_request
Source code in src/async_kernel/kernel.py
578 579 580 581 582 | |
delete_subshell_request
async
¶
Handle an delete subshell request.
Source code in src/async_kernel/kernel.py
584 585 586 587 588 | |
list_subshell_request
async
¶
Handle an list subshell request.
Source code in src/async_kernel/kernel.py
590 591 592 | |
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
594 595 596 597 598 599 600 601 602 603 604 605 | |
do_complete
async
¶
Matches signature of ipykernel.kernelbase.Kernel.do_complete.
Source code in src/async_kernel/kernel.py
607 608 609 | |
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
611 612 613 614 615 | |
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
617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 | |
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
639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 | |
getpass
¶
getpass(prompt='', stream=None) -> str
Matches signature of ipykernel.kernelbase.Kernel.getpass.
Source code in src/async_kernel/kernel.py
661 662 663 | |
raw_input
¶
raw_input(prompt='') -> str
Matches signature of ipykernel.kernelbase.Kernel.raw_input.
Source code in src/async_kernel/kernel.py
665 666 667 | |