asyncshell
Classes:
-
AsyncInteractiveShell–An IPython InteractiveShell adapted to work with Async kernel.
-
AsyncInteractiveSubshell–An asynchronous interactive subshell for managing isolated execution contexts within an async kernel.
-
KernelInterruptError–Raised to interrupt the kernel.
-
AsyncDisplayHook–A displayhook subclass that publishes data using iopub_send.
-
AsyncDisplayPublisher–A display publisher that publishes data using iopub_send.
-
SubshellManager–Manages all instances of subshells.
-
KernelMagics–Extra magics for async kernel.
Attributes:
-
__all__–
AsyncInteractiveShell
¶
Bases: InteractiveShell
An IPython InteractiveShell adapted to work with Async kernel.
Notable differences
- All execute requests are run asynchronously.
- Supports a soft timeout specified via tags
timeout=<value in seconds>1. - Gui event loops(tk, qt, ...) are not presently supported.
- Not all features are support (see "not-supported" features listed below).
user_nsanduser_global_nsare same dictionary which is a fixedLastUpdatedDict.
-
When the execution time exceeds the timeout value, the code execution will "move on". ↩
- Reference
-
Reference
asyncshell
AsyncInteractiveSubshell
Methods:
-
execute_request–Handle a execute request.
-
do_complete_request–Handle a completion request.
-
is_complete_request–Handle an is_complete request.
-
inspect_request–Handle a inspect request.
-
history_request–Handle a history request.
-
init_magics–Initialize magics.
-
enable_gui–Enable a given gui.
Attributes:
-
timeout–A timeout in seconds to complete execute requests.
-
stop_on_error_time_offset–An offset to add to the cancellation time to catch late arriving execute requests.
-
run_cell(Callable[..., ExecutionResult]) –Not supported - use execute_request instead.
-
debug–Not supported - use the built in debugger instead.
Source code in src/async_kernel/asyncshell.py
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 | |
timeout
class-attribute
instance-attribute
¶
timeout = CFloat(0.0)
A timeout in seconds to complete execute requests.
stop_on_error_time_offset
class-attribute
instance-attribute
¶
stop_on_error_time_offset = Float(0.0)
An offset to add to the cancellation time to catch late arriving execute requests.
run_cell
class-attribute
instance-attribute
¶
run_cell: Callable[..., ExecutionResult] = None
Not supported - use execute_request instead.
debug
class-attribute
instance-attribute
¶
debug = None
Not supported - use the built in debugger instead.
execute_request
async
¶
execute_request(
code: str = "",
silent: bool = False,
store_history: bool = True,
user_expressions: dict[str, str] | None = None,
allow_stdin: bool = True,
stop_on_error: bool = True,
**_ignored,
) -> Content
Handle a execute request.
-
Reference
asyncshell
AsyncInteractiveShell
Source code in src/async_kernel/asyncshell.py
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 | |
do_complete_request
async
¶
Handle a completion request.
Source code in src/async_kernel/asyncshell.py
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 | |
is_complete_request
async
¶
Handle an is_complete request.
Source code in src/async_kernel/asyncshell.py
422 423 424 425 426 427 428 | |
inspect_request
async
¶
Handle a inspect request.
Source code in src/async_kernel/asyncshell.py
430 431 432 433 434 435 436 437 438 439 440 441 | |
history_request
async
¶
history_request(
*,
output: bool = False,
raw: bool = True,
hist_access_type: str,
session: int = 0,
start: int = 1,
stop: int | None = None,
n: int = 10,
pattern: str = "*",
unique: bool = False,
**_ignored,
) -> Content
Handle a history request.
Source code in src/async_kernel/asyncshell.py
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 | |
init_magics
¶
init_magics() -> None
Initialize magics.
Source code in src/async_kernel/asyncshell.py
498 499 500 501 502 | |
enable_gui
¶
enable_gui(gui=None) -> None
Enable a given gui.
Supported guis
- inline
- ipympl
- tk
- qt
-
Reference
asyncshell
AsyncInteractiveShell
Source code in src/async_kernel/asyncshell.py
504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 | |
AsyncInteractiveSubshell
¶
Bases: AsyncInteractiveShell
An asynchronous interactive subshell for managing isolated execution contexts within an async kernel.
Each subshell has a unique user_ns, but shares its user_global_ns with the main shell
(which is also the user_ns of the main shell).
Call subshell.stop(force=True) to stop a
protected subshell when it is no longer required.
Attributes:
-
stopped–Indicates whether the subshell has been stopped.
-
protected–If True, prevents the subshell from being stopped unless forced.
-
pending_manager–Tracks pending started in the context of the subshell.
-
subshell_id(Fixed[Self, str]) –Unique identifier for the subshell.
Methods:
-
stop–Stops the subshell, deactivating pending operations and removing it from the manager.
- Reference asyncshell
Source code in src/async_kernel/asyncshell.py
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 | |
stop
¶
stop(*, force=False) -> None
Stop this subshell.
Source code in src/async_kernel/asyncshell.py
572 573 574 575 576 577 578 | |
KernelInterruptError
¶
Bases: Exception
Raised to interrupt the kernel.
Source code in src/async_kernel/asyncshell.py
45 46 | |
AsyncDisplayHook
¶
Bases: DisplayHook
A displayhook subclass that publishes data using iopub_send.
This is intended to work with an InteractiveShell instance. It sends a dict of different representations of the object.
Methods:
-
start_displayhook–Start the display hook.
-
write_output_prompt–Write the output prompt.
-
write_format_data–Write format data to the message.
-
finish_displayhook–Finish up all displayhook activities.
Source code in src/async_kernel/asyncshell.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 | |
start_displayhook
¶
start_displayhook() -> None
Start the display hook.
Source code in src/async_kernel/asyncshell.py
68 69 70 71 | |
write_output_prompt
¶
write_output_prompt() -> None
Write the output prompt.
Source code in src/async_kernel/asyncshell.py
73 74 75 76 | |
write_format_data
¶
write_format_data(format_dict, md_dict=None) -> None
Write format data to the message.
Source code in src/async_kernel/asyncshell.py
78 79 80 81 82 | |
finish_displayhook
¶
finish_displayhook() -> None
Finish up all displayhook activities.
Source code in src/async_kernel/asyncshell.py
84 85 86 87 88 89 | |
AsyncDisplayPublisher
¶
Bases: DisplayPublisher
A display publisher that publishes data using iopub_send.
Methods:
-
publish–Publish a display-data message.
-
clear_output–Clear output associated with the current execution (cell).
-
register_hook–Register a hook for when publish is called.
Source code in src/async_kernel/asyncshell.py
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 | |
publish
¶
publish(
data: dict[str, Any],
metadata: dict | None = None,
*,
transient: dict | None = None,
update: bool = False,
**kwargs,
) -> None
Publish a display-data message.
Parameters:
-
(data¶dict[str, Any]) –A mime-bundle dict, keyed by mime-type.
-
(metadata¶dict | None, default:None) –Metadata associated with the data.
-
(transient¶dict | None, default:None) –Transient data that may only be relevant during a live display, such as display_id. Transient data should not be persisted to documents.
-
(update¶bool, default:False) –If True, send an update_display_data message instead of display_data.
Source code in src/async_kernel/asyncshell.py
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 | |
clear_output
¶
clear_output(wait: bool = False) -> None
Clear output associated with the current execution (cell).
Parameters:
-
(wait¶bool, default:False) –If True, the output will not be cleared immediately, instead waiting for the next display before clearing. This reduces bounce during repeated clear & display loops.
Source code in src/async_kernel/asyncshell.py
135 136 137 138 139 140 141 142 143 144 145 | |
register_hook
¶
Register a hook for when publish is called.
The hook should return the message or None.
Only return None when the message should not be sent.
Source code in src/async_kernel/asyncshell.py
147 148 149 150 151 152 153 | |
SubshellManager
¶
Manages all instances of subshells.
Warning:
**Do NOT instantiate directly.** Instead access the instance via [async_kernel.kernel.Kernel.subshell_manager][].
-
Reference
kernel
Kernelsubshell_manager
Methods:
-
create_subshell–Create a new instance of the default subshell class.
-
get_shell–Get a subshell or the main shell.
-
delete_subshell–Stop a subshell unless it is protected.
-
stop_all_subshells–Stop all current subshells.
Source code in src/async_kernel/asyncshell.py
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 | |
create_subshell
¶
create_subshell(*, protected: bool = True) -> AsyncInteractiveSubshell
Create a new instance of the default subshell class.
Call subshell.stop(force=True) to stop a
protected subshell when it is no longer required.
Parameters:
Source code in src/async_kernel/asyncshell.py
596 597 598 599 600 601 602 603 604 605 606 | |
get_shell
¶
get_shell(subshell_id: str) -> AsyncInteractiveSubshell
get_shell(subshell_id: None = ...) -> AsyncInteractiveShell
get_shell(
subshell_id: str | None | NoValue = NoValue,
) -> AsyncInteractiveShell | AsyncInteractiveSubshell
Get a subshell or the main shell.
Parameters:
Source code in src/async_kernel/asyncshell.py
618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 | |
delete_subshell
¶
delete_subshell(subshell_id: str) -> None
Stop a subshell unless it is protected.
Parameters:
Source code in src/async_kernel/asyncshell.py
636 637 638 639 640 641 642 643 644 | |
stop_all_subshells
¶
stop_all_subshells(*, force: bool = False) -> None
Stop all current subshells.
Parameters:
Source code in src/async_kernel/asyncshell.py
646 647 648 649 650 651 652 653 | |
KernelMagics
¶
Bases: Magics
Extra magics for async kernel.
Methods:
-
connect_info–Print information for connecting other clients to this kernel.
-
callers–Print a table of Callers, indicating its status including: -running - protected - on the current thread.
-
subshell–Print subshell info ref.
Source code in src/async_kernel/asyncshell.py
656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 | |
connect_info
¶
connect_info(_) -> None
Print information for connecting other clients to this kernel.
Source code in src/async_kernel/asyncshell.py
660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 | |
callers
¶
callers(_) -> None
Print a table of Callers, indicating its status including: -running - protected - on the current thread.
Source code in src/async_kernel/asyncshell.py
680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 | |
subshell
¶
subshell(_) -> None
Print subshell info ref.
See also
Source code in src/async_kernel/asyncshell.py
697 698 699 700 701 702 703 704 705 706 707 708 709 | |