Asynchronous Sessions¶
Skaha now supports asynchronous sessions using the AsyncSession
class while maintaining 1-to-1 compatibility with the Session
class.
Bases: SkahaClient
Asynchronous Skaha Session Management Client.
This class provides methods to manage sessions in the Skaha system, including fetching session details, creating new sessions, retrieving logs, and destroying existing sessions.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
SkahaClient
|
SkahaClient
|
Base HTTP client for making API requests. |
required |
Examples:
>>> from skaha.session import AsyncSession
>>> session = AsyncSession(
server="https://skaha.example.com",
version="v1",
token="token",
timeout=30,
concurrency=100,
loglevel=40,
)
create(name, image, cores=2, ram=4, kind='headless', gpu=None, cmd=None, args=None, env=None, replicas=1)
async
¶
Launch a skaha session.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
A unique name for the session. |
required |
image
|
str
|
Container image to use for the session. |
required |
cores
|
int
|
Number of cores. Defaults to 2. |
2
|
ram
|
int
|
Amount of RAM (GB). Defaults to 4. |
4
|
kind
|
str
|
Type of skaha session. Defaults to "headless". |
'headless'
|
gpu
|
Optional[int]
|
Number of GPUs. Defaults to None. |
None
|
cmd
|
Optional[str]
|
Command to run. Defaults to None. |
None
|
args
|
Optional[str]
|
Arguments to the command. Defaults to None. |
None
|
env
|
Optional[Dict[str, Any]]
|
Environment variables to inject. Defaults to None. |
None
|
replicas
|
int
|
Number of sessions to launch. Defaults to 1. |
1
|
Notes
The name of the session suffixed with the replica number. eg. test-1, test-2 Each container will have the following environment variables injected: * REPLICA_ID - The replica number * REPLICA_COUNT - The total number of replicas
Returns:
Type | Description |
---|---|
List[str]
|
List[str]: A list of session IDs for the launched sessions. |
Examples:
destroy(ids)
async
¶
Destroy skaha session[s].
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ids
|
Union[str, List[str]]
|
Session ID[s]. |
required |
Returns:
Type | Description |
---|---|
Dict[str, bool]
|
Dict[str, bool]: A dictionary of session IDs |
Dict[str, bool]
|
and a bool indicating if the session was destroyed. |
Examples:
destroy_with(prefix, kind='headless', status='Succeeded')
async
¶
Destroy skaha session[s] matching search criteria.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
prefix
|
str
|
Prefix to match in the session name. |
required |
kind
|
KINDS
|
Type of skaha session. Defaults to "headless". |
'headless'
|
status
|
STATUS
|
Status of the session. Defaults to "Succeeded". |
'Succeeded'
|
Returns:
Type | Description |
---|---|
Dict[str, bool]
|
Dict[str, bool]: A dictionary of session IDs |
Dict[str, bool]
|
and a bool indicating if the session was destroyed. |
Notes
The prefix is case-sensitive. This method is useful for destroying multiple sessions at once.
Examples:
fetch(kind=None, status=None, view=None)
async
¶
List open sessions for the user.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
kind
|
Optional[KINDS]
|
Session kind. Defaults to None. |
None
|
status
|
Optional[STATUS]
|
Session status. Defaults to None. |
None
|
view
|
Optional[VIEW]
|
Session view level. Defaults to None. |
None
|
Notes
By default, only the calling user's sessions are listed. If views is set to 'all', all user sessions are listed (with limited information).
Returns:
Name | Type | Description |
---|---|---|
list |
List[Dict[str, str]]
|
Sessions information. |
Examples:
>>> from skaha.session import AsyncSession
>>> session = AsyncSession()
>>> await session.fetch(kind="notebook")
[{'id': 'vl91sfzz',
'userid': 'brars',
'runAsUID': '166169204',
'runAsGID': '166169204',
'supplementalGroups': [34241,
34337,
35124,
36227,
1902365706,
1454823273,
1025424273],
'appid': '<none>',
'image': 'images-rc.canfar.net/skaha/skaha-notebook:22.09-test',
'type': 'notebook',
'status': 'Running',
'name': 'notebook1',
'startTime': '2025-03-05T21:48:29Z',
'expiryTime': '2025-03-09T21:48:29Z',
'connectURL': 'https://canfar.net/session/notebook/some/url',
'requestedRAM': '8G',
'requestedCPUCores': '2',
'requestedGPUCores': '0',
'ramInUse': '<none>',
'gpuRAMInUse': '<none>',
'cpuCoresInUse': '<none>',
'gpuUtilization': '<none>'}]
info(ids)
async
¶
Get information about session[s].
Parameters:
Name | Type | Description | Default |
---|---|---|---|
id
|
Union[List[str], str]
|
Session ID[s]. |
required |
Returns:
Type | Description |
---|---|
List[Dict[str, Any]]
|
Dict[str, Any]: Session information. |
Examples:
logs(ids, verbose=False)
async
¶
Get logs from a session[s].
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ids
|
Union[List[str], str]
|
Session ID[s]. |
required |
verbose
|
bool
|
Print logs to stdout. Defaults to False. |
False
|
Returns:
Type | Description |
---|---|
Optional[Dict[str, str]]
|
Dict[str, str]: Logs in text/plain format. |
Examples:
stats()
async
¶
Get statistics for the entire skaha cluster.
Returns:
Type | Description |
---|---|
Dict[str, Any]
|
Dict[str, Any]: Cluster statistics. |
Examples:
>>> from skaha.session import AsyncSession
>>> session = AsyncSession()
>>> await session.stats()
{'instances': {
'session': 88, 'desktopApp': 30, 'headless': 0, 'total': 118},
'cores': {'requestedCPUCores': 377,
'coresAvailable': 960,
'maxCores': {'cores': 32, 'withRam': '147Gi'}},
'ram': {'maxRAM': {'ram': '226Gi', 'withCores': 32}}}