Skip to content

Conversation

Zsailer
Copy link
Member

@Zsailer Zsailer commented Sep 29, 2025

Addresses #763.

This PR introduces a state machine for tracking kernel lifecycle states using a mixin approach that can be easily adopted by any existing kernel manager implementation.

The KernelManagerStateMixin design allows developers to add state tracking to any existing kernel
manager
by simply including it in the inheritance chain - no configuration or code changes required.
This opt-in approach means:

  • Existing implementations continue working unchanged
  • Developers can choose when and where to add state tracking
  • Zero risk of breaking current functionality
  • Easy to test and evaluate before wider adoption

I intentionally did not add this to the default kernel managers yet, allowing the community to
evaluate the approach first.

Usage

from jupyter_client import KernelManagerStateMixin

class MyKernelManager(KernelManagerStateMixin, ExistingKernelManager):
    pass  # No changes needed to existing logic

manager = MyKernelManager()
manager.start_kernel()
print(manager.is_started)  # True

Introduces a comprehensive state machine implementation for tracking kernel
lifecycle states during management operations.

Key features:
- KernelManagerStateMixin for automatic state tracking via method wrapping
- LifecycleState string-based enum for clean API usage
- state_transition decorator for custom state management scenarios
- Automatic error handling with state reset to UNKNOWN on failures
- Support for both sync and async kernel operations
- Non-intrusive mixin design compatible with existing kernel managers

States tracked: UNKNOWN, STARTING, STARTED, RESTARTING, RESTARTED,
TERMINATING, DEAD with automatic transitions during start/restart/shutdown
operations.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant