Skip to content

Worker manager

A class to manage workers for an app.

You access this object via App.workers or Widget.workers.

WorkerManager class

def __init__(self, app):

An object to manager a number of workers.

You will not have to construct this class manually, as widgets, screens, and apps have a worker manager accessibly via a workers attribute.

Parameters
Name Type Description Default
app App

An App instance.

required

add_worker method

def add_worker(self, worker, start=True, exclusive=True):

Add a new worker.

Parameters
Name Type Description Default
worker Worker

A Worker instance.

required
start bool

Start the worker if True, otherwise the worker must be started manually.

True
exclusive bool

Cancel all workers in the same group as worker.

True

cancel_all method

def cancel_all(self):

Cancel all workers.

cancel_group method

def cancel_group(self, node, group):

Cancel a single group.

Parameters
Name Type Description Default
node DOMNode

Worker DOM node.

required
group str

A group name.

required
Returns
Type Description
list[Worker]

A list of workers that were cancelled.

cancel_node method

def cancel_node(self, node):

Cancel all workers associated with a given node

Parameters
Name Type Description Default
node DOMNode

A DOM node (widget, screen, or App).

required
Returns
Type Description
list[Worker]

List of cancelled workers.

start_all method

def start_all(self):

Start all the workers.

wait_for_complete async

def wait_for_complete(self, workers=None):

Wait for workers to complete.

Parameters
Name Type Description Default
workers Iterable[Worker] | None

An iterable of workers or None to wait for all workers in the manager.

None