Skip to content

Add State Machine Handling to KernelManager #763

@blink1073

Description

@blink1073

In #751 we explored better internal state management for the KernelManager class.

We decided there to adopt the transitions library. It is MIT licensed, already on conda-forge, and lets you produce diagrams from your state machine.
We can produce the state machine graph image automatically, backed by CI.

A rough sketch looks like:

Currently server adds "execution_state" to the manager object based on kernel status messages. I think eventually we should move that logic here, but it doesn't need to be in this PR.

The states used here could mirror the ones used in JupyterLab :

  • Unknown
  • Starting
  • Running (Maps to Idle and Busy execution states)
  • Terminating
  • Restarting
  • Dead (with optional traceback)

We are Unknown to start. State transitions are as follows:

  • Unknown -> Starting
  • Starting -> Running or Dead
  • Running -> Terminating, Restarting, or Dead
  • Terminating -> Dead
  • Restarting -> Running or Dead
  • Dead -> Starting

Then we have a state: Unicode() trait and a convenience wait_for_state() method that takes
an optional desired state or returns for any state change. It would also raise an exception if it
gets to Dead state and it wasn't the expected state, along with the traceback.

The state trait can also be observed directly.

We also have an exception: Unicode() trait that is set when an exception leads to a Dead status.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions