Start and stop app

This guide explains how to manage application sessions using API

Introduction

Supervisely Ecosystem has hundreds of different apps from different categories: from import and data manipulation to neural network training. The huge value for end users is in applications.

However, sometimes it is needed to run multiple apps in a specific order to solve custom task and it may be a bit inconvenient or boring for users. Supervisely SDK allows automate this procedure and build custom pipelines of apps where multiple apps can be run one by one or in parallel in a specific order.

This tutorial demonstrates basic functionality for managing app sessions from Python code: how to start and stop an app, how to wait for a task to end, handle exceptions and iterate over application sessions in your team.

πŸ“— Everything you need to reproduce this tutorial is on GitHub: source code and demo data.

How to debug this tutorial

Step 1. Prepare ~/supervisely.env file with credentials. Learn more here.

Step 2. Clone repository with source code and demo data and create Virtual Environment.

git clone https://github.com/supervisely-ecosystem/automation-with-python-sdk-and-api
cd automation-with-python-sdk-and-api
./create_venv.sh

Step 3. Open repository directory in Visual Studio Code.

code -r .

Step 4. Go into the folder with the source code for the current tutorial and prepare values inexamples/start-stop-app/local.env file before debug

Step 5. Start debugging examples/start-stop-app/main.py

Python code

Import libraries

Init API client

Init API for communicating with Supervisely Instance. First, we load environment variables with credentials and additional demo values from local.env :

Init variables with demo data

We are going to run export-to-pascal-voc application. You can change it to any other app and slightly change the script.

ℹ️ If you need to run a private application, you can obtain app_slug from the application's page:

Slug for a private application

Load information about app from Ecosystem

To work with app sessions we need module_id - identifier of application in Ecosystem.

Output:

It can be obtained by using application slug (text identifier in Ecosystem) value in the following formatsupervisely-ecosystem/<repository-name>)

Application slug - text identifier in Ecosystem

Or alternatively, you can copy module ID from the application page in Ecosystem on your Supervisely Instance.

Copy module ID from application page in Ecosystem

App input arguments

Every app has its own input arguments. They are defined by optional configurable parameters in the modal dialog window before the app starts.

And also in most cases there is a valiable for the context menu of some Supervisely entity. For example, if the application starts from the context menu of images project - id of this project is the required input argument.

Supervisely SDK alows to get the list of needed arguments for every app and also validates missing ones automatically.

Output:

As you can see from the output, the application has two optional values with already defined default values (we can change them) and that app starts from the context menu of the images project. It means that one argument images_project is required.

Python SDK allows to generate needed arguments and validate them:

Here is the correspondence between input arguments and the modal window. It is worth mentioning that now all apps have paramaters in modal window. So that arguments_help method helps to identify existing parameters automatically.

App input arguments and modal dialog window

Start application

Output:

Wait until app is finished

Option 1 - wait task finish or specific task status

Option 2 - wait until task end without any limitations (can work infinite in the worst case)

Option 3 - set timeout and handle corresponding exceptions:

As you can see there is a method for getting the app session status api.app.get_status. You can use it to implement your custom logic for waitings or timeouts.

Method api.app.stop is used to send stop signal to the app.

List existing app sessions in Team

Let's list all sessions of a specific app in our team with additional optional filtering by statuses [finished].

Output:

Recap

In this tutorial we learned how to use python to

  • get information from Ecosystem about certain application

  • how to work and prepare input arguments for application

  • how to start application

  • how to wait session of application, monitor its status (task status) and handle exceptions

  • how to stop application

Last updated

Was this helpful?