Provides various interactions with compute sessions in Backend.AI.
The term ‘kernel’ is now deprecated and we prefer ‘compute sessions’. However, for historical reasons and to avoid confusion with client sessions, we keep the backward compatibility with the naming of this API function class.
For multi-container sessions, all methods take effects to the master container only, except
restart()methods. So it is the user’s responsibility to distribute uploaded files to multiple containers using explicit copies or virtual folders which are commonly mounted to all containers belonging to the same compute session.
The client session instance that this function class is bound to.
get_or_create(lang, *, client_token=None, mounts=None, envs=None, resources=None, cluster_size=1, tag=None, owner_access_key=None)¶
Get-or-creates a compute session. If client_token is
None, it creates a new compute session as long as the server has enough resources and your API key has remaining quota. If client_token is a valid string and there is an existing compute session with the same token and the same lang, then it returns the
Kernelinstance representing the existing session.
str) – The image name and tag for the compute session. Example:
python:3.6-ubuntu. Check out the full list of available images in your server using (TODO: new API).
int) – The number of containers in this compute session. Must be at least 1.
owner – An optional access key that owns the created session. (Only available to administrators)
- Return type
Destroys the compute session. Since the server literally kills the container(s), all ongoing executions are forcibly interrupted.
Restarts the compute session. The server force-destroys the current running container(s), but keeps their temporary scratch directories intact.
Tries to interrupt the current ongoing code execution. This may fail without any explicit errors depending on the code being executed.
Gets the auto-completion candidates from the given code string, as if a user has pressed the tab key just after the code in IDEs.
Depending on the language of the compute session, this feature may not be supported. Unsupported sessions returns an empty list.
Retrieves a brief information about the compute session.
Retrieves the console log of the compute session container.
execute(run_id=None, code=None, mode='query', opts=None)¶
Executes a code snippet directly in the compute session or sends a set of build/clean/execute commands to the compute session.
For more details about using this API, please refer the official API documentation.
str]) – A unique identifier for a particular run loop. In the first call, it may be
Noneso that the server auto-assigns one. Subsequent calls must use the returned
runIdvalue to request continuation or to send user inputs.
str) – A constant string which is one of
upload(files, basedir=None, show_progress=False)¶
Uploads the given list of files to the compute session. You may refer them in the batch-mode execution or from the code executed in the server afterwards.
The list of file paths in the client-side. If the paths include directories, the location of them in the compute session is calculated from the relative path to basedir and all intermediate parent directories are automatically created if not exists.
For example, if a file path is
test/data.txt) where basedir is
/home/user(or the current working directory is
/home/user), the uploaded file is located at
/home/work/test/data.txtin the compute session container.
bool) – Displays a progress bar during uploads.
download(files, dest='.', show_progress=False)¶
Downloads the given list of files from the compute session.
bool) – Displays a progress bar during downloads.
Gets the list of files in the given path inside the compute session container.
Opens a pseudo-terminal of the kernel (if supported) streamed via websockets.