cut 3.3.0
Loading...
Searching...
No Matches
task.task.Task Class Reference

Provides a quick way to execute long running procedures. More...

Public Member Functions

 __new__ (Type cls, Callable fn, *args, **kwargs)
 Method that indicates how a new object for this class is created.
 
 __init__ (self, Callable fn, *args, **kwargs)
 Initializes a new Task, saving within its attributes the arguments passed.
 
 set_thread_pool (self, QThreadPool tp)
 Sets a custom QThreadPool in which the Task will be executed.
 
QThreadPool get_thread_pool (self)
 Gets the currently used QThreadPool.
 
int start (self, bool with_qrunnable=True)
 Starts the task, by requesting a common QThreadPool the execution of this object (which it accepts, as it is a QRunnable).
 
 run (self)
 Method that contains the logic that is pushed to the secondary thread.
 

Detailed Description

Provides a quick way to execute long running procedures.

Attention
To use this class, please import with the following statement:
from elt.cut.task.task import Task
Implements Task and TaskSignals classes.

Provides a quick way to execute long running procedures in a separate thread. If the user may choose, they can set up connections to signals that are triggered in specific circumstances.

Inherits from QRunnable to handle task setup and wrap-up. Since QRunnable is not a QObject, it cannot have signals and slot: Thus, this is delegated to a WorkerSignals class that is owned by the WorkerIO.

In this example, it is shown how to use this class::

from elt.cut.task.task import Task
task = Task(function_to_execute)
task.signals.result.connect(function_to_publish_result)
task.signals.finished.connect(function_when_finished)
task.start()

The start() method requests a common QThreadPool to execute this object.

Note
This class is intended to simplify threading, and is in no way a complete replacement for all situations.

Encapsulates a task to be executed, and executes it in another thread.

Constructor & Destructor Documentation

◆ __init__()

task.task.Task.__init__ ( self,
Callable fn,
* args,
** kwargs )

Initializes a new Task, saving within its attributes the arguments passed.

Parameters
[in]fnThe function callback to run on this worker thread. Supplied args and kwargs will be passed through to the runner.
[in]argsArguments to pass to the callback function
[in]kwargsKeywords to pass to the callback function

Member Function Documentation

◆ __new__()

task.task.Task.__new__ ( Type cls,
Callable fn,
* args,
** kwargs )

Method that indicates how a new object for this class is created.

Implements singleton pattern for the ThreadPool. The first object created will store a "static" reference of the same object, and from then on the "static" reference is returned.

◆ get_thread_pool()

QThreadPool task.task.Task.get_thread_pool ( self)

Gets the currently used QThreadPool.

Returns
QThreadPool The thread pool currently used by the task.

◆ run()

task.task.Task.run ( self)

Method that contains the logic that is pushed to the secondary thread.

This executes the method fn, with arguments args and kwargs, as indicated during initialization.

◆ set_thread_pool()

task.task.Task.set_thread_pool ( self,
QThreadPool tp )

Sets a custom QThreadPool in which the Task will be executed.

Developer is responsible for its lifecycle.

◆ start()

int task.task.Task.start ( self,
bool with_qrunnable = True )

Starts the task, by requesting a common QThreadPool the execution of this object (which it accepts, as it is a QRunnable).

If no threads are available, the task will be queued for execution.

Parameters
[in]with_qrunnableUses QRunnable instead of taurus.Manager for task job execution. In particular, QRunnables offer more feedback capabilities.
Returns
Task id as an int.

The documentation for this class was generated from the following file: