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
Parameter Default Description
app
App
required

An App instance.

add_worker method

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

Add a new worker.

Parameters
Parameter Default Description
worker
Worker
required

A Worker instance.

start
bool
True

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

exclusive
bool
True

Cancel all workers in the same group as worker.

cancel_all method

def cancel_all(self):

Cancel all workers.

cancel_group method

def cancel_group(self, node, group):

Cancel a single group.

Parameters
Parameter Default Description
node
DOMNode
required

Worker DOM node.

group
str
required

A group name.

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
Parameter Default Description
node
DOMNode
required

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

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
Parameter Default Description
workers
Iterable[Worker] | None
None

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