Class: QgsTaskManager¶
Task manager for managing a set of long-running QgsTask
tasks.
This class can be created directly, or accessed via
QgsApplication.taskManager()
.
Class Hierarchy¶
Base classes¶
Methods
Returns a list of the active (queued or running) tasks. |
|
Adds a task to the manager. |
|
Instructs all tasks tracked by the manager to terminate. |
|
Returns the number of tasks tracked by the manager. |
|
Returns the number of active (queued or running) tasks. |
|
Returns |
|
Returns a list of layers on which as task is dependent. |
|
Returns the task with matching ID. |
|
Returns the unique task ID corresponding to a task managed by the class. |
|
Returns all tasks tracked by the manager. |
|
Returns a list of tasks which depend on a layer. |
|
Returns the threadpool utilized by the task manager. |
|
Triggers a task, e.g. as a result of a GUI interaction. |
Signals
Emitted when all tasks are complete |
|
Emitted when the number of active tasks changes |
|
Will be emitted when only a single task remains to complete and that task has reported a progress change |
|
Will be emitted when a task reports a progress change |
|
Will be emitted when a task reports a status change |
|
Emitted when a task is about to be deleted |
|
Emitted when a new task has been added to the manager |
|
Emitted when a task is triggered. |
- class qgis.core.QgsTaskManager[source]¶
Bases:
QObject
- __init__(parent: QObject | None = None)
Constructor for QgsTaskManager.
- Parameters:
parent (Optional[QObject] = None) – parent QObject
- class TaskDefinition¶
Bases:
object
Definition of a task for inclusion in the manager.
- dependentTasks: QgsTaskList¶
List of dependent tasks which must be completed before task can run. If any dependent tasks are canceled this task will also be canceled. Dependent tasks must also be added to the task manager for proper handling of dependencies.
- activeTasks(self) List[QgsTask] ¶
Returns a list of the active (queued or running) tasks.
See also
- Return type:
List[QgsTask]
- addTask(self, task: QgsTask | None, priority: int = 0) int [source]¶
Adds a task to the manager. Ownership of the task is transferred to the manager, and the task manager will be responsible for starting the task. The priority argument can be used to control the run queue’s order of execution, with larger numbers taking precedence over lower priority numbers.
- Return type:
int
- Returns:
unique task ID, or 0 if task could not be added
- Parameters:
task (Optional[QgsTask])
priority (int = 0)
- addTask(self, task: QgsTaskManager.TaskDefinition, priority: int = 0) int [source]
Adds a task to the manager, using a full task definition (including dependency handling). Ownership of the task is transferred to the manager, and the task manager will be responsible for starting the task. The priority argument can be used to control the run queue’s order of execution, with larger numbers taking precedence over lower priority numbers.
- Return type:
int
- Returns:
unique task ID, or 0 if task could not be added
- Parameters:
priority (int = 0)
- cancelAll(self)[source]¶
Instructs all tasks tracked by the manager to terminate. Individual tasks may take some time to cancel, or may totally ignore this instruction. Calling this does not block but will instead signal the tasks to cancel and then return immediately.
- countActiveTasks(self, includeHidden: bool = True) int [source]¶
Returns the number of active (queued or running) tasks.
The
includeHidden
argument dictates whether hidden tasks should be shown.See also
See also
- Parameters:
includeHidden (bool = True)
- Return type:
int
- signal countActiveTasksChanged(count: int)[source]¶
Emitted when the number of active tasks changes
See also
- Parameters:
count (int)
- dependenciesSatisfied(self, taskId: int) bool [source]¶
Returns
True
if all dependencies for the specified task are satisfied- Parameters:
taskId (int)
- Return type:
bool
- dependentLayers(self, taskId: int) List[QgsMapLayer] ¶
Returns a list of layers on which as task is dependent. The task will automatically be canceled if any of these layers are about to be removed.
- Parameters:
taskId (int) – task ID
- Return type:
List[QgsMapLayer]
- Returns:
list of layers
See also
- signal finalTaskProgressChanged(progress: float)[source]¶
Will be emitted when only a single task remains to complete and that task has reported a progress change
- Parameters:
progress (float) – percent of progress, from 0.0 - 100.0
- signal progressChanged(taskId: int, progress: float)[source]¶
Will be emitted when a task reports a progress change
- Parameters:
taskId (int) – ID of task
progress (float) – percent of progress, from 0.0 - 100.0
- signal statusChanged(taskId: int, status: int)[source]¶
Will be emitted when a task reports a status change
- Parameters:
taskId (int) – ID of task
status (int) – new task status
- task(self, id: int) QgsTask | None [source]¶
Returns the task with matching ID.
- Parameters:
id (int) – task ID
- Return type:
Optional[QgsTask]
- Returns:
task if found, or
None
- signal taskAboutToBeDeleted(taskId: int)[source]¶
Emitted when a task is about to be deleted
- Parameters:
taskId (int) – ID of task
- signal taskAdded(taskId: int)[source]¶
Emitted when a new task has been added to the manager
- Parameters:
taskId (int) – ID of task
- taskId(self, task: QgsTask | None) int [source]¶
Returns the unique task ID corresponding to a task managed by the class.
- Parameters:
task (Optional[QgsTask]) – task to find
- Return type:
int
- Returns:
task ID, or -1 if task not found
- signal taskTriggered(task: QgsTask)[source]¶
Emitted when a
task
is triggered. This occurs when a user clicks on the task from the QGIS GUI, and can be used to show detailed progress reports or re-open a related dialog.See also
- Parameters:
task (QgsTask)
- tasksDependentOnLayer(self, layer: QgsMapLayer | None) List[QgsTask] ¶
Returns a list of tasks which depend on a layer.
See also
- Parameters:
layer (Optional[QgsMapLayer])
- Return type:
List[QgsTask]
- threadPool(self) QThreadPool | None [source]¶
Returns the threadpool utilized by the task manager.
Added in version 3.34.
- Return type:
Optional[QThreadPool]