Skip to content

Session

app.application.managers.session

View source code

Module for session; coordinates session and worker lifecycles.

See Also
  • SessionInitializer — attaches runtime collaborators to new sessions
  • Session — infrastructure runtime object managed here

Layer: Application. Context: Coordinates session and worker lifecycles at this architectural boundary.

SessionManager

Owns the dict of open Session objects and coordinates their application-layer lifecycle.

The manager keeps session creation and initialization in one place, while the expensive runtime bootstrap (video reader, runtime view_state, decode worker) is delegated to SessionInitializer.

PARAMETER DESCRIPTION
app

Application that owns the manager and is notified when the active session changes.

TYPE: Application

session_initializer

Initializer that constructs and wires new sessions.

TYPE: SessionInitializer | None DEFAULT: None

active_session: Session | None property

Return the currently active session, if any.

RETURNS DESCRIPTION
Session | None

Active session, or None when no session is active.

active_session_id: SessionId | None property writable

Return the identifier of the active session, if any.

RETURNS DESCRIPTION
SessionId | None

Active session identifier, or None when no session is active.

all_session_ids: Iterable[SessionId] property

Return identifiers for all managed sessions.

RETURNS DESCRIPTION
Iterable[SessionId]

An iterable view of the managed session identifiers.

all_sessions: Iterable[Session] property

Return all sessions managed by this manager.

RETURNS DESCRIPTION
Iterable[Session]

An iterable view of the managed session objects.

__init__(app: Application, session_initializer: SessionInitializer | None = None) -> None

bind_session_service(session_service: SessionService)

Bind the session service used for session lifecycle operations.

PARAMETER DESCRIPTION
session_service

Service used to coordinate session lifecycle workflows.

TYPE: SessionService

close_all() -> None

Closes all sessions and clears the session manager.

Flow
  1. Iterate through all sessions and call their close() method.
  2. Clear the internal session dictionary.
  3. Reset the active session ID to an empty view_state using SessionId("").

create_session_from_video_path(path: str)

Create and register a session for a video file.

PARAMETER DESCRIPTION
path

Filesystem path of the video to open.

TYPE: str

Note

Duplicate paths are rejected; video-open and stream errors are logged and skipped without creating a session.

discard_session(s_id: SessionId) -> None

Close and remove the session identified by its session ID.

PARAMETER DESCRIPTION
s_id

Identifier of the session to close and remove.

TYPE: SessionId

get_current_frame_for_session_id(s_id: SessionId) -> RGBFrame | None

Retrieve the frame at the session's current playback index.

PARAMETER DESCRIPTION
s_id

Identifier of the session to query.

TYPE: SessionId

RETURNS DESCRIPTION
RGBFrame | None

Cached or decoded RGB frame, or None if no frame is available.

get_frame_for_session_id_by_index(frame_index: int, s_id: SessionId) -> RGBFrame | None

Fetches a specific frame directly from the O(1) Ring Buffer, or triggers a seek.

PARAMETER DESCRIPTION
frame_index

Zero-based frame index to retrieve.

TYPE: int

s_id

Identifier of the session containing the frame.

TYPE: SessionId

RETURNS DESCRIPTION
RGBFrame | None

Decoded RGB frame, or None if it is unavailable.

get_next_frame_for_session_id(s_id: SessionId) -> RGBFrame | None

Advance the session to its next frame and retrieve it.

PARAMETER DESCRIPTION
s_id

Identifier of the session to advance.

TYPE: SessionId

RETURNS DESCRIPTION
RGBFrame | None

Next RGB frame, or None if no frame is available.

get_previous_frame_for_session_id(s_id: SessionId) -> RGBFrame | None

Move the session to its previous frame and retrieve it.

PARAMETER DESCRIPTION
s_id

Identifier of the session to rewind.

TYPE: SessionId

RETURNS DESCRIPTION
RGBFrame | None

Previous RGB frame, or None if no frame is available.

get_session_by_id(s_id: SessionId) -> Session

Return the session identified by s_id.

PARAMETER DESCRIPTION
s_id

Identifier of the session to retrieve.

TYPE: SessionId

RETURNS DESCRIPTION
Session

Matching session.

RAISES DESCRIPTION
KeyError

If s_id is not managed by this manager.

get_session_state_by_id(s_id: SessionId) -> SessionState

Return the state object belonging to s_id.

PARAMETER DESCRIPTION
s_id

Identifier of the session to inspect.

TYPE: SessionId

RETURNS DESCRIPTION
SessionState

The SessionState for s_id, including its playback, settings, and

SessionState

annotation state.

initialize_active_session()

One-time helper to initialize the active session.

stop_all_playback() -> None

Stop all playback.