Shortcuts

LightningWork

class lightning_app.core.LightningWork(parallel=False, cache_calls=True, raise_exception=True, host='127.0.0.1', port=None, local_build_config=None, cloud_build_config=None, cloud_compute=None, run_once=None)[source]

Bases: object

LightningWork, or Work in short, is a building block for long-running jobs.

The LightningApp runs its LightningFlow component within an infinite loop and track the LightningWork status update.

Use LightningWork for third-party services or for launching heavy jobs such as downloading data, training or serving a model.

Each LightningWork is running in its own independent process. Works are self-isolated from the rest, e.g any state changes happening within the work will be reflected within the flow but not the other way around.

Parameters
  • parallel (bool) – Whether to run in parallel mode or not. When False, the flow waits for the work to finish.

  • cache_calls (bool) – Whether the run method should cache its input arguments and not run again when provided with the same arguments in subsequent calls.

  • raise_exception (bool) – Whether to re-raise an exception in the flow when raised from within the work run method.

  • host (str) – Bind socket to this host

  • port (Optional[int]) – Bind socket to this port. Be default, this is None and should be called within your run method.

  • local_build_config (Optional[BuildConfig]) – The local BuildConfig isn’t used until Lightning supports DockerRuntime.

  • cloud_build_config (Optional[BuildConfig]) – The cloud BuildConfig enables user to easily configure machine before running this work.

  • run_once (Optional[bool]) – Deprecated in favor of cache_calls. This will be removed soon.

Learn More About Lightning Work Inner Workings


_aggregate_status_timeout(statuses)[source]

Method used to return the first request and the total count of timeout after the latest succeeded status.

Return type

WorkStatus

static _is_state_attribute(name)[source]

Every public attribute is part of the state by default and all protected (prefixed by ‘_’) or private (prefixed by ‘__’) attributes are not.

Exceptions are listed in the _INTERNAL_STATE_VARS class variable.

Return type

bool

on_exception(exception)[source]

Override to customize how to handle exception in the run method.

on_exit()[source]

Override this hook to add your logic when the work is exiting.

run(*args, **kwargs)[source]

Override to add your own logic.

Raises

LightningPlatformException – If resource exceeds platform quotas or other constraints.

stop()[source]

Stops LightingWork component and shuts down hardware provisioned via L.CloudCompute.

property cache_calls: bool[source]

Returns whether the run method should cache its input arguments and not run again when provided with the same arguments in subsequent calls.

Return type

bool

property cloud_build_config: lightning_app.utilities.packaging.build_config.BuildConfig[source]

Returns the cloud build config used to prepare the selected cloud hardware.

Return type

BuildConfig

property has_failed: bool[source]

Return whether the work has failed.

Return type

bool

property has_started: bool[source]

Return whether the work has started.

Return type

bool

property has_stopped: bool[source]

Return whether the work has started.

Return type

bool

property has_succeeded: bool[source]

Return whether the work has succeeded.

Return type

bool

property has_timeout: bool[source]

Return whether the work has time-out.

Return type

bool

property host: str[source]

Returns the current host of the work.

Return type

str

property internal_ip: str[source]

The internal ip address of this LightningWork, reachable by other Work locally and in the cloud.

By default, this attribute returns the empty string and the ip address will only be returned once the work runs. Locally, the address is 127.0.0.1 and in the cloud it will be determined by the cluster.

Return type

str

property is_pending: bool[source]

Return whether the work is pending.

Return type

bool

property is_running: bool[source]

Return whether the work is running.

Return type

bool

property name[source]

Returns the name of the LightningWork.

property num_successes: int[source]

Returns the number of successful runs.

Return type

int

property num_timeouts: int[source]

Return the number of timeout status since the lastest succeeded run.

Return type

int

property parallel: bool[source]

Whether to run in parallel mode or not.

When parallel is False, the flow waits for the work to finish.

Return type

bool

property state[source]

Returns the current state of this LightningWork.

property status: lightning_app.utilities.enum.WorkStatus[source]

Return the current status of the work.

All statuses are stored in the state.

Return type

WorkStatus

property statuses: List[lightning_app.utilities.enum.WorkStatus][source]

Return all the status of the work.

Return type

List[WorkStatus]

property url: str[source]

Returns the current url of the work.

Return type

str


© Copyright Copyright (c) 2021-2022, Lightning-AI et al...

Built with Sphinx using a theme provided by Read the Docs.