lenskit.parallel.AccelTask#

class lenskit.parallel.AccelTask[R]#

Bases: Protocol

An accelerated task, implemented by the accelerator backend.

This protocol is implemented by long-running accelerator tasks, and is used by run_accel_task() to run these tasks with cancellation, progress reporting, and suitable thread pool management.

The runner will spawn a background thread and call the task’s invoke() method in that thread. The main thread will poll for completion and progress reports.

invoke()#

Run this task and return its result. Must only be called once for a given accelerator task. Will be run on the offloaded execution thread.

Return type:

R

cancel()#

Cancel this task.

Note

Will usually not be called from the same thread as invoke().

current_progress()#

Poll the current progress of this task.

Note

Will usually not be called from the same thread as invoke().

Return type:

int | tuple[int, int] | None