SnakeBridge.SessionManager (SnakeBridge v0.15.0)

Copy Markdown View Source

Manages Python session lifecycle with process monitoring.

Sessions are automatically released when all owner processes die, preventing memory leaks in long-running applications.

Cleanup logs are opt-in via config. Use config :snakebridge, session_cleanup_log_level: :debug to enable.

Summary

Functions

Returns a specification to start this module under a supervisor.

Lists all refs in a session.

Registers a ref with its session for tracking.

Registers a session owner process. The session will be released when the last owner dies.

Explicitly releases a session and all its refs.

Checks if a session exists.

Unregisters a session without releasing refs on the Python side.

Types

ref()

@type ref() :: map()

session_id()

@type session_id() :: String.t()

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

list_refs(session_id)

@spec list_refs(session_id()) :: [ref()]

Lists all refs in a session.

register_ref(session_id, ref)

@spec register_ref(session_id(), ref()) :: :ok | {:error, :session_not_found}

Registers a ref with its session for tracking.

register_session(session_id, owner_pid)

@spec register_session(session_id(), pid()) :: :ok

Registers a session owner process. The session will be released when the last owner dies.

release_session(session_id)

@spec release_session(session_id()) :: :ok

Explicitly releases a session and all its refs.

session_exists?(session_id)

@spec session_exists?(session_id()) :: boolean()

Checks if a session exists.

start_link(opts \\ [])

unregister_session(session_id)

@spec unregister_session(session_id()) :: :ok

Unregisters a session without releasing refs on the Python side.

Typically called when manually cleaning up before process death, or when the caller has already released the session.