interface
Modules:
-
base–The base class definition to interface with the kernel.
-
callable–A collection of objects to provide a kernel interface based on callbacks.
-
ip_app–An IPython application with a zmq interface.
-
zmq–Defines a base kernel interface using zmq sockets.
Classes:
-
BaseInterface–The base class for kernel interface (singleton).
-
HasInterface–A mixin class providing a reference to the global interface.
Functions:
-
start_kernel_callable_interface–Start the global interface as an instance of CallableInterface.
-
launch_interface–Launch a kernel interface blocking until it has stopped.
BaseInterface
¶
Bases: Application, AsyncContextManagerMixin, Generic[T_shell_co]
The base class for kernel interface (singleton).
The interface creates the kernel and provides external communication. It is also
the parent object for all objects that subclass from HasInterface. Configurable
objects that subclass from HasInterface inherit their configuration from the
interface (Application).
Usage
launch:
Interface.launch_instance()
async with Interface() as interface:
interface.kernel
...
-
Reference
interface
ZMQInterfacealiases
Methods:
-
initialized–Has an instance been created?
-
instance–Get the singleton instance that was created using
launch_instance. -
initialize–Initialize the interface DO NOT CALL DIRECTLY.
-
start–Start the interface blocking until it stops.
-
run–Run the kernel.
-
stop–Stop the kernel and this interface.
-
input_request–Forward an input request to the frontend.
-
msg–Create a new message.
-
iopub_send–Send an iopub message.
Attributes:
-
classes(ClassesType) –The classes registered with the interface.
-
aliases(dict[str | tuple[str, ...], str]) – -
flags– -
name–The name of the kernel used in the kernelspec.
-
host(TraitType[Hosts | None, Hosts | None]) –The name of a (gui) event loop (if one is used).
-
host_options–Options for starting the loop.
-
backend(TraitType[Backend, Backend]) –The type of asynchronous backend used. Options are 'asyncio' or 'trio'.
-
backend_options–Options for starting the backend.
-
interface_class(Type[type[Self], type[Self] | str]) –The interface class to use when launching.
-
kernel_class(Type[type[Kernel[Self, T_shell_co]], type[Kernel[Self, T_shell_co]] | str]) –The Kernel class to use when creating the kernel.
-
shell_class(Type[type[T_shell_co], type[T_shell_co] | str]) –The class to use for shells and subshells.
-
quiet–Only send stdout/stderr to output stream.
-
launcher–The value used to import the interface using async_kernel.kernelspec.import_launcher.
-
kernel(Fixed[Self, Kernel[Self, T_shell_co]]) –The kernel.
-
callers(Fixed[Self, dict[Literal[shell, control], Caller]]) –The caller associated with the kernel once it has started.
-
started–A Pending that is set when the interface has started.
-
stopping–A Pending that is set when stop is called.
Source code in src/async_kernel/interface/base.py
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 | |
classes
class-attribute
instance-attribute
¶
classes: ClassesType = final([])
The classes registered with the interface.
aliases
class-attribute
instance-attribute
¶
aliases: dict[str | tuple[str, ...], str] = {
("name", "n"): "BaseInterface.name",
"launcher": "BaseInterface.launcher",
"timeout": "BaseShell.timeout",
"kernel_class": "BaseInterface.kernel_class",
"shell_class": "BaseInterface.shell_class",
"help_links": "Kernel.help_links",
"supported_features": "Kernel.supported_features",
"interface_class": "BaseInterface.interface_class",
} | Application.aliases
-
Reference
interface
ZMQInterfacealiases
flags
class-attribute
instance-attribute
¶
flags = {
"quiet": (
{"BaseInterface": {"quiet": True}},
"Only send stdout/stderr to output stream.",
),
"no-quiet": (
{"BaseInterface": {"quiet": False}},
"Only send stdout/stderr to output stream.",
),
} | Application.flags
name
class-attribute
instance-attribute
¶
name = traitlets.Unicode('async').tag(config=True)
The name of the kernel used in the kernelspec.
host
class-attribute
instance-attribute
¶
host: TraitType[Hosts | None, Hosts | None] = traitlets.UseEnum(
Hosts, default_value=None, allow_none=True
).tag(config=True)
The name of a (gui) event loop (if one is used).
host_options
class-attribute
instance-attribute
¶
host_options = DictValueLiteralEval(allow_none=True).tag(config=True)
Options for starting the loop.
backend
class-attribute
instance-attribute
¶
The type of asynchronous backend used. Options are 'asyncio' or 'trio'.
backend_options
class-attribute
instance-attribute
¶
backend_options = DictValueLiteralEval(allow_none=True).tag(config=True)
Options for starting the backend.
interface_class
class-attribute
instance-attribute
¶
interface_class: Type[type[Self], type[Self] | str] = traitlets.Type(
"async_kernel.interface.base.BaseInterface"
).tag(config=True)
The interface class to use when launching.
kernel_class
class-attribute
instance-attribute
¶
kernel_class: Type[
type[Kernel[Self, T_shell_co]], type[Kernel[Self, T_shell_co]] | str
] = traitlets.Type("async_kernel.Kernel").tag(config=True)
The Kernel class to use when creating the kernel.
shell_class
class-attribute
instance-attribute
¶
shell_class: Type[type[T_shell_co], type[T_shell_co] | str] = traitlets.Type(
"async_kernel.shell.ipshell.IPShell", "async_kernel.shell.BaseShell"
).tag(config=True)
The class to use for shells and subshells.
quiet
class-attribute
instance-attribute
¶
quiet = traitlets.Bool(True).tag(config=True)
Only send stdout/stderr to output stream.
launcher
class-attribute
instance-attribute
¶
launcher = traitlets.Unicode('').tag(config=True)
The value used to import the interface using async_kernel.kernelspec.import_launcher.
kernel
class-attribute
instance-attribute
¶
kernel: Fixed[Self, Kernel[Self, T_shell_co]] = Fixed(
lambda c: c["owner"].kernel_class(c["owner"], c["owner"].shell_class)
)
The kernel.
callers
class-attribute
instance-attribute
¶
The caller associated with the kernel once it has started.
started
class-attribute
instance-attribute
¶
A Pending that is set when the interface has started.
stopping
class-attribute
instance-attribute
¶
A Pending that is set when stop is called.
initialized
classmethod
¶
initialized() -> bool
Has an instance been created?
Source code in src/async_kernel/interface/base.py
214 215 216 217 218 | |
instance
classmethod
¶
instance() -> Self
Get the singleton instance that was created using launch_instance.
Source code in src/async_kernel/interface/base.py
220 221 222 223 224 225 226 227 228 229 230 | |
initialize
¶
Initialize the interface DO NOT CALL DIRECTLY.
Source code in src/async_kernel/interface/base.py
283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 | |
start
¶
start() -> None
Start the interface blocking until it stops.
Warning
- Running in a thread other than the 'MainThread' is permitted, but discouraged.
- Blocking calls can only be interrupted in the 'MainThread' because 'threads cannot be destroyed, stopped, suspended, resumed, or interrupted'.
- Some libraries may assume the call is occurring in the 'MainThread'.
- If there is an
asyncioortrioevent loop already running in the desired thread; start asynchronously instead (async with interface: ...).
Source code in src/async_kernel/interface/base.py
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 | |
run
async
¶
Run the kernel.
Parameters:
-
(stopped¶Callable[[], Any] | None, default:None) –An optional callback that is called when the kernel has stopped.
This method requires that a Caller instance does not already exist in the current thread.
Source code in src/async_kernel/interface/base.py
383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 | |
stop
¶
stop() -> None
Stop the kernel and this interface.
Source code in src/async_kernel/interface/base.py
400 401 402 403 404 405 406 407 408 | |
input_request
¶
Forward an input request to the frontend.
Parameters:
-
(prompt¶str) –The user prompt.
-
(password¶bool, default:False) –If the prompt should be considered as a password.
Source code in src/async_kernel/interface/base.py
410 411 412 413 414 415 416 417 418 | |
msg
¶
msg(
msg_type: str | MsgType,
*,
content: T | None = None,
parent: Message | dict[str, Any] | None = None,
header: MsgHeader | dict[str, Any] | None = None,
metadata: dict[str, Any] | None = None,
channel: Channel = shell,
) -> Message[T]
Create a new message.
Source code in src/async_kernel/interface/base.py
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 | |
iopub_send
¶
iopub_send(
msg_or_type: Message[dict[str, Any]] | dict[str, Any] | str,
*,
content: Content | None = None,
metadata: dict[str, Any] | None = None,
parent: dict[str, Any] | MsgHeader | None | NoValue = NoValue,
ident: bytes | list[bytes] | None = None,
buffers: list[bytes] | None = None,
) -> None
Send an iopub message.
Source code in src/async_kernel/interface/base.py
454 455 456 457 458 459 460 461 462 463 464 465 | |
HasInterface
¶
Bases: Generic[T_interface_co]
A mixin class providing a reference to the global interface.
This class is designed to be compatible with Configurable objects enabling the sharing of configuration and log objects. The global interface must exist before creating subclass instances using this mixin.
Attributes:
-
parent(T_interface_co) –The interface at the time of creation.
-
config(Config) –A reference to the
parent.config.
Source code in src/async_kernel/interface/base.py
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 | |
start_kernel_callable_interface
async
¶
start_kernel_callable_interface(
*,
send: Callable[[str, list | None, bool], None | str],
stopped: Callable[[], None],
settings: dict | None = None,
) -> Handlers
Start the global interface as an instance of CallableInterface.
Parameters:
-
(send¶Callable[[str, list | None, bool], None | str]) –A callback responsible for sending messages from the kernel on all channels.
-
(stopped¶Callable[[], None]) –A callback that is called once the kernel has stopped.
-
(settings¶dict | None, default:None) –Additional settings to configure the interface/kernel/shell etc using traitlets config conventions. The settings are converted to argv using async_kernel.kernelspec.make_argv. All settings, including aliases and flags are accepted. flags should be passed as
'flags': [<flag1>, <flag2>, ...].
Tip
- To list all config options available for a
CallableInterfaceuse the command:async-kernel --help-all --interface_class=async_kernel.interface.callable.CallableInterface
Source code in src/async_kernel/interface/__init__.py
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | |
launch_interface
¶
launch_interface(settings: dict) -> None
Launch a kernel interface blocking until it has stopped.
Notes
- Available in CPython.
- 'interface_class' can be specified in settings as a subclass of BaseInterface or as an importable string.
settingsare NOT loaded.sys.argvis used for configuration. Useasync-kernel --help-allto see all configuration options.- traitlets configuration documentation.
Source code in src/async_kernel/interface/__init__.py
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 | |
The base class definition to interface with the kernel.
Classes:
-
BaseInterface–The base class for kernel interface (singleton).
-
HasInterface–A mixin class providing a reference to the global interface.
BaseInterface
¶
Bases: Application, AsyncContextManagerMixin, Generic[T_shell_co]
The base class for kernel interface (singleton).
The interface creates the kernel and provides external communication. It is also
the parent object for all objects that subclass from HasInterface. Configurable
objects that subclass from HasInterface inherit their configuration from the
interface (Application).
Usage
launch:
Interface.launch_instance()
async with Interface() as interface:
interface.kernel
...
-
Reference
interface
ZMQInterfacealiases
Methods:
-
initialized–Has an instance been created?
-
instance–Get the singleton instance that was created using
launch_instance. -
initialize–Initialize the interface DO NOT CALL DIRECTLY.
-
start–Start the interface blocking until it stops.
-
run–Run the kernel.
-
stop–Stop the kernel and this interface.
-
input_request–Forward an input request to the frontend.
-
msg–Create a new message.
-
iopub_send–Send an iopub message.
Attributes:
-
classes(ClassesType) –The classes registered with the interface.
-
aliases(dict[str | tuple[str, ...], str]) – -
flags– -
name–The name of the kernel used in the kernelspec.
-
host(TraitType[Hosts | None, Hosts | None]) –The name of a (gui) event loop (if one is used).
-
host_options–Options for starting the loop.
-
backend(TraitType[Backend, Backend]) –The type of asynchronous backend used. Options are 'asyncio' or 'trio'.
-
backend_options–Options for starting the backend.
-
interface_class(Type[type[Self], type[Self] | str]) –The interface class to use when launching.
-
kernel_class(Type[type[Kernel[Self, T_shell_co]], type[Kernel[Self, T_shell_co]] | str]) –The Kernel class to use when creating the kernel.
-
shell_class(Type[type[T_shell_co], type[T_shell_co] | str]) –The class to use for shells and subshells.
-
quiet–Only send stdout/stderr to output stream.
-
launcher–The value used to import the interface using async_kernel.kernelspec.import_launcher.
-
kernel(Fixed[Self, Kernel[Self, T_shell_co]]) –The kernel.
-
callers(Fixed[Self, dict[Literal[shell, control], Caller]]) –The caller associated with the kernel once it has started.
-
started–A Pending that is set when the interface has started.
-
stopping–A Pending that is set when stop is called.
Source code in src/async_kernel/interface/base.py
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 | |
classes
class-attribute
instance-attribute
¶
classes: ClassesType = final([])
The classes registered with the interface.
aliases
class-attribute
instance-attribute
¶
aliases: dict[str | tuple[str, ...], str] = {
("name", "n"): "BaseInterface.name",
"launcher": "BaseInterface.launcher",
"timeout": "BaseShell.timeout",
"kernel_class": "BaseInterface.kernel_class",
"shell_class": "BaseInterface.shell_class",
"help_links": "Kernel.help_links",
"supported_features": "Kernel.supported_features",
"interface_class": "BaseInterface.interface_class",
} | Application.aliases
-
Reference
interface
ZMQInterfacealiases
flags
class-attribute
instance-attribute
¶
flags = {
"quiet": (
{"BaseInterface": {"quiet": True}},
"Only send stdout/stderr to output stream.",
),
"no-quiet": (
{"BaseInterface": {"quiet": False}},
"Only send stdout/stderr to output stream.",
),
} | Application.flags
name
class-attribute
instance-attribute
¶
name = traitlets.Unicode('async').tag(config=True)
The name of the kernel used in the kernelspec.
host
class-attribute
instance-attribute
¶
host: TraitType[Hosts | None, Hosts | None] = traitlets.UseEnum(
Hosts, default_value=None, allow_none=True
).tag(config=True)
The name of a (gui) event loop (if one is used).
host_options
class-attribute
instance-attribute
¶
host_options = DictValueLiteralEval(allow_none=True).tag(config=True)
Options for starting the loop.
backend
class-attribute
instance-attribute
¶
The type of asynchronous backend used. Options are 'asyncio' or 'trio'.
backend_options
class-attribute
instance-attribute
¶
backend_options = DictValueLiteralEval(allow_none=True).tag(config=True)
Options for starting the backend.
interface_class
class-attribute
instance-attribute
¶
interface_class: Type[type[Self], type[Self] | str] = traitlets.Type(
"async_kernel.interface.base.BaseInterface"
).tag(config=True)
The interface class to use when launching.
kernel_class
class-attribute
instance-attribute
¶
kernel_class: Type[
type[Kernel[Self, T_shell_co]], type[Kernel[Self, T_shell_co]] | str
] = traitlets.Type("async_kernel.Kernel").tag(config=True)
The Kernel class to use when creating the kernel.
shell_class
class-attribute
instance-attribute
¶
shell_class: Type[type[T_shell_co], type[T_shell_co] | str] = traitlets.Type(
"async_kernel.shell.ipshell.IPShell", "async_kernel.shell.BaseShell"
).tag(config=True)
The class to use for shells and subshells.
quiet
class-attribute
instance-attribute
¶
quiet = traitlets.Bool(True).tag(config=True)
Only send stdout/stderr to output stream.
launcher
class-attribute
instance-attribute
¶
launcher = traitlets.Unicode('').tag(config=True)
The value used to import the interface using async_kernel.kernelspec.import_launcher.
kernel
class-attribute
instance-attribute
¶
kernel: Fixed[Self, Kernel[Self, T_shell_co]] = Fixed(
lambda c: c["owner"].kernel_class(c["owner"], c["owner"].shell_class)
)
The kernel.
callers
class-attribute
instance-attribute
¶
The caller associated with the kernel once it has started.
started
class-attribute
instance-attribute
¶
A Pending that is set when the interface has started.
stopping
class-attribute
instance-attribute
¶
A Pending that is set when stop is called.
initialized
classmethod
¶
initialized() -> bool
Has an instance been created?
Source code in src/async_kernel/interface/base.py
214 215 216 217 218 | |
instance
classmethod
¶
instance() -> Self
Get the singleton instance that was created using launch_instance.
Source code in src/async_kernel/interface/base.py
220 221 222 223 224 225 226 227 228 229 230 | |
initialize
¶
Initialize the interface DO NOT CALL DIRECTLY.
Source code in src/async_kernel/interface/base.py
283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 | |
start
¶
start() -> None
Start the interface blocking until it stops.
Warning
- Running in a thread other than the 'MainThread' is permitted, but discouraged.
- Blocking calls can only be interrupted in the 'MainThread' because 'threads cannot be destroyed, stopped, suspended, resumed, or interrupted'.
- Some libraries may assume the call is occurring in the 'MainThread'.
- If there is an
asyncioortrioevent loop already running in the desired thread; start asynchronously instead (async with interface: ...).
Source code in src/async_kernel/interface/base.py
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 | |
run
async
¶
Run the kernel.
Parameters:
-
(stopped¶Callable[[], Any] | None, default:None) –An optional callback that is called when the kernel has stopped.
This method requires that a Caller instance does not already exist in the current thread.
Source code in src/async_kernel/interface/base.py
383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 | |
stop
¶
stop() -> None
Stop the kernel and this interface.
Source code in src/async_kernel/interface/base.py
400 401 402 403 404 405 406 407 408 | |
input_request
¶
Forward an input request to the frontend.
Parameters:
-
(prompt¶str) –The user prompt.
-
(password¶bool, default:False) –If the prompt should be considered as a password.
Source code in src/async_kernel/interface/base.py
410 411 412 413 414 415 416 417 418 | |
msg
¶
msg(
msg_type: str | MsgType,
*,
content: T | None = None,
parent: Message | dict[str, Any] | None = None,
header: MsgHeader | dict[str, Any] | None = None,
metadata: dict[str, Any] | None = None,
channel: Channel = shell,
) -> Message[T]
Create a new message.
Source code in src/async_kernel/interface/base.py
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 | |
iopub_send
¶
iopub_send(
msg_or_type: Message[dict[str, Any]] | dict[str, Any] | str,
*,
content: Content | None = None,
metadata: dict[str, Any] | None = None,
parent: dict[str, Any] | MsgHeader | None | NoValue = NoValue,
ident: bytes | list[bytes] | None = None,
buffers: list[bytes] | None = None,
) -> None
Send an iopub message.
Source code in src/async_kernel/interface/base.py
454 455 456 457 458 459 460 461 462 463 464 465 | |
HasInterface
¶
Bases: Generic[T_interface_co]
A mixin class providing a reference to the global interface.
This class is designed to be compatible with Configurable objects enabling the sharing of configuration and log objects. The global interface must exist before creating subclass instances using this mixin.
Attributes:
-
parent(T_interface_co) –The interface at the time of creation.
-
config(Config) –A reference to the
parent.config.
Source code in src/async_kernel/interface/base.py
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 | |
A collection of objects to provide a kernel interface based on callbacks.
Classes:
-
Handlers–Handlers returned by async_kernel.interface.callable.CallableInterface when it is started.
-
CallableInterface–A callback based interface to interact with the kernel using serialized messages.
Handlers
¶
Bases: TypedDict
Handlers returned by async_kernel.interface.callable.CallableInterface when it is started.
Attributes:
-
handle_msg(Callable[[str, list[bytes] | list[bytearray] | None]]) –Handle messages from the client.
-
stop(Callable[[], None]) –Stop the kernel.
Source code in src/async_kernel/interface/callable.py
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | |
handle_msg
instance-attribute
¶
Handle messages from the client.
The handler requires two positional arguments
- The message serialized as a JSON string. The channel ("shell" or "control" ) should also be included in the Message under the key "channel".
- A list of buffers if there are any, or None if there are no buffers.
CallableInterface
¶
Bases: BaseInterface[T_shell_co], Generic[T_shell_co]
A callback based interface to interact with the kernel using serialized messages.
Usage:
```python
from async_kernel.interface.callable import CallableInterface
# Start the kernel providing the necessary callbacks.
kernel_interface = await CallableInterface(options).start(send=..., stopped=...)
# Pass messages to the kernel.
kernel_interface["handle_msg"](msg, buffer)
# Stop the kernel.
kernel_interface["stop"](msg, buffer)
```
See also: - [async_kernel.typing.CallableInterfaceReturnArgs]
Methods:
-
start_async–Start the kernel.
Attributes:
Source code in src/async_kernel/interface/callable.py
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 | |
host
class-attribute
instance-attribute
¶
Not yet supported
start_async
async
¶
start_async(
*, send: Callable[[str, list | None, bool], None | str], stopped: Callable[[], None]
) -> Handlers
Start the kernel.
Parameters:
-
(send¶Callable[[str, list | None, bool], None | str]) –The function to send kernel messages to the client. It must accept
- A json string of the message.
- A list of buffers, or None if there are no buffers.
- A boolean value that indicates a response is required for the stdio channel.
-
(stopped¶Callable[[], None]) –A callback that is called once the kernel has stopped.
Returns: A pending that when resolved returns the message handler callback.
Source code in src/async_kernel/interface/callable.py
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 | |
Defines a base kernel interface using zmq sockets.
Classes:
-
ZMQInterface–The base kernel interface using ZMQ sockets.
ZMQInterface
¶
Bases: BaseInterface[T_shell_co], ConnectionFileMixin, Generic[T_shell_co]
The base kernel interface using ZMQ sockets.
Methods:
-
iopub_send–Send a message on the zmq iopub socket.
-
receive_msg_loop–Opens a zmq socket for the channel, receives messages and calls the message handler.
Attributes:
-
aliases– -
session– -
transport(CaselessStrEnum[str]) –Transport for sockets.
Source code in src/async_kernel/interface/zmq.py
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 | |
aliases
class-attribute
instance-attribute
¶
aliases = BaseInterface.aliases | {
("f", "connection_file"): "ZMQInterface.connection_file",
"host": "ZMQInterface.host",
"host_options": "ZMQInterface.host_options",
"backend_options": "ZMQInterface.backend_options",
"backend": "ZMQInterface.backend",
"ip": "ZMQInterface.ip",
"hb": "ZMQInterface.hb_port",
"shell": "ZMQInterface.shell_port",
"iopub": "ZMQInterface.iopub_port",
"stdin": "ZMQInterface.stdin_port",
"control": "ZMQInterface.control_port",
"transport": "ZMQInterface.transport",
}
transport
class-attribute
instance-attribute
¶
transport: CaselessStrEnum[str] = traitlets.CaselessStrEnum(
["tcp", "ipc"] if sys.platform == "linux" else ["tcp"], default_value="tcp"
).tag(config=True)
Transport for sockets.
iopub_send
¶
iopub_send(
msg_or_type: Message[dict[str, Any]] | dict[str, Any] | str,
*,
content: Content | None = None,
metadata: dict[str, Any] | None = None,
parent: dict[str, Any] | MsgHeader | None | NoValue = NoValue,
ident: bytes | list[bytes] | None = None,
buffers: list[bytes] | None = None,
) -> None
Send a message on the zmq iopub socket.
Source code in src/async_kernel/interface/zmq.py
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 | |
receive_msg_loop
¶
Opens a zmq socket for the channel, receives messages and calls the message handler.
Source code in src/async_kernel/interface/zmq.py
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 | |
An IPython application with a zmq interface.
Classes:
-
IPApp–An IPython application with a zmq interface.
IPApp
¶
Bases: ZMQInterface[T_ipshell_co], BaseIPythonApplication, InteractiveShellApp, Generic[T_ipshell_co]
An IPython application with a zmq interface.
Attributes:
-
description–A description to use for the command line interface.
-
aliases– -
flags–
Source code in src/async_kernel/interface/ip_app.py
27 28 29 30 31 32 33 34 35 36 37 38 39 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 | |
description
class-attribute
instance-attribute
¶
description = traitlets.Unicode(
"async-kernel: A Jupyter kernel providing an asynchronous IPython shell."
).tag(config=True)
A description to use for the command line interface.
aliases
class-attribute
instance-attribute
¶
aliases = (
ZMQInterface.aliases
| {
"profile-dir": "ProfileDir.location",
"profile": "BaseIPythonApplication.profile",
"ipython-dir": "BaseIPythonApplication.ipython_dir",
"config": "BaseIPythonApplication.extra_config_file",
}
| shell_aliases
)
flags
class-attribute
instance-attribute
¶
flags = (
ZMQInterface.flags
| {
"automagic": (
{"InteractiveShell": {"automagic": True}},
"Turn on the auto calling of magic commands. Type %%magic at the IPython prompt for more information.",
),
"no-automagic": (
{"InteractiveShell": {"automagic": False}},
"Turn off the auto calling of magic commands.",
),
}
| shell_flags
)