Menu
Introduction
Getting Started
Developer guide
Release
Architecture
CLI
Technical documentations
Version
Publication date

Mar 9, 2022

Confidentiality
Public
Reactions
2
Share

ScenarioProxy

Object to simplify scenario creation, configuration and run. This can be used in a Jupyter Notebook

:raises Exception: [description] :return: [description] :rtype: [type]

Functions
__init__

This create a scenario in the database with the provided Task or Protocol

protocol_type : type[gws_core.protocol.protocol.Protocol] | None
folder : gws_core.folder.space_folder.SpaceFolder | None
scenario title
title : str - ''
scenario title
creation_type : ScenarioCreationType - ScenarioCreationType.AUTO
type of the created scenario
scenario_id : str | None
If provided, other parameters are ignored, it loads an existing scenario
add_tag
tag : Tag
add_tags
tags : list
add_to_queue
delete
get_model
Return type : Scenario
get_model_id
Return type : str
get_protocol

retrieve the main protocol of the scenario

Return type : ProtocolProxy
get_url
Return type : str
is_finished
Return type : bool
is_running
Return type : bool
is_success
Return type : bool
refresh
Return type : ScenarioProxy
reset

Reset the scenario to draft and delete all logs and progress

Return type : ScenarioProxy
reset_error_processes

Reset all processes in error of the scenario

Return type : ScenarioProxy
run

Execute the scenario synchronously and block until it is finished.

The scenario runs in a forked sub-process (ProcessDb) so it can be stopped, then this method waits for it to complete and raises if it errored.

.. warning:: This forks the current process. It is safe in tests, CLI commands and the scenario queue subprocess, but must never be called from a FastAPI request handler (i.e. from the running HTTP server). The fork duplicates the server's listening socket and event-loop state, which blocks every other HTTP request until the scenario finishes, and the forked download keeps running even if the client disconnects.

From a request handler, run the scenario asynchronously instead:
use :meth:`run_async` and return immediately, then poll the scenario
status from the front-end (see the ``*_async`` methods on
``ResourceTransfertService``, ``ConverterService``, etc.).

This method enforces the rule above: calling it while this process is the HTTP server raises a RuntimeError instead of silently degrading the server. The allow_in_http_server escape hatch exists only for call sites that are not yet converted and must be reviewed individually; do not use it for new code.

auto_delete_if_error : bool - False
delete the scenario if it ends in error, defaults to False
allow_in_http_server : bool - False
bypass the request-handler guard. Reserved for not-yet-converted call sites; do not use in new code
run_async

Run the scenario in a separate CLI process but don't wait for it to finish.

Uses a CLI subprocess (like the queue runner) instead of fork to avoid inheriting the parent's server socket and event loop state, which can block other HTTP requests.

Return type : ScenarioWaiterBasic
stop
stop_or_remove_from_queue

Stop the scenario or remove it from the queue depending on its current status.

  • If the scenario is running in an external lab, stop all running importing scenarios.
  • If the scenario is running locally, stop it.
  • If the scenario is in queue, remove it from the queue.
Return type : ScenarioProxy
from_existing_scenario @staticmethod

Create a ScenarioProxy from an existing scenario

scenario_id : str
id of the scenario
Return type : ScenarioProxy
Shine Logo
Technical bricks to reuse or customize

Have you developed a brick?

Share it to accelerate projects for the entire community.