Qudi
Public Member Functions | Public Attributes | Static Public Attributes | List of all members
generic_task.InterruptableTask Class Reference

This class represents a task in a module that can be safely executed by checking preconditions and pausing other tasks that are being executed as well. More...

Inheritance diagram for generic_task.InterruptableTask:
Inheritance graph
[legend]
Collaboration diagram for generic_task.InterruptableTask:
Collaboration graph
[legend]

Public Member Functions

def __init__ (self, name, runner, references, config, kwargs)
 Create an Interruptable task. More...
 
def log (self)
 Returns a logger object.
 
def onchangestate (self, e)
 Fysom callback for state transition. More...
 
def checkStartPrerequisites (self)
 Check whether this task can be started by checking if all tasks to be paused are either stopped or can be paused. More...
 
def checkExtraStartPrerequisites (self)
 If your task has extra prerequisites that are not covered by checking if a certain task can be paused, overwrite this function when sub-classing. More...
 
def checkPausePrerequisites (self)
 Check if task is allowed to pause based on external state. More...
 
def checkExtraPausePrerequisites (self)
 If yout task has prerequisites for pausing, overwrite this function when subclassing and put the check here. More...
 
def canPause (self)
 Check if task can pause based on its own state only.
 
def startTask (self)
 Implement the operation to start your task here.
 
def runTaskStep (self)
 Implement one work step of your task here. More...
 
def pauseTask (self)
 Implement the operations necessary to pause your task here.
 
def resumeTask (self)
 Implement the operations necessary to resume your task from being paused here.
 
def cleanupTask (self)
 If your task leaves behind any undesired state, take care to remove it in this function. More...
 

Public Attributes

 lock
 
 name
 
 interruptable
 
 success
 
 runner
 
 ref
 
 config
 
 result
 

Static Public Attributes

 sigDoStart = QtCore.Signal()
 
 sigStarted = QtCore.Signal()
 
 sigNextTaskStep = QtCore.Signal()
 
 sigDoPause = QtCore.Signal()
 
 sigPaused = QtCore.Signal()
 
 sigDoResume = QtCore.Signal()
 
 sigResumed = QtCore.Signal()
 
 sigDoFinish = QtCore.Signal()
 
 sigFinished = QtCore.Signal()
 
 sigStateChanged = QtCore.Signal(object)
 
dictionary prePostTasks = {}
 
dictionary pauseTasks = {}
 
list requiredModules = []
 

Detailed Description

This class represents a task in a module that can be safely executed by checking preconditions and pausing other tasks that are being executed as well.

The task can also be paused, given that the preconditions for pausing are met.

State diagram for InterruptableTask:

stopped -> starting --------—> running ------—> finishing -* ^ | _______| ^_________ | |<------—* v | v | pausing -> paused -> resuming | | | | | ^ v v | |----------—<-----—|-------—<------—|-----—<----—

Each state has a transition state that allow for checks, synchronizatuion and for parts of the task to influence its own execution via signals. This also allows the TaskRunner to be informed about what the task is doing and ensuring that a task is executed in the correct thread.

Constructor & Destructor Documentation

◆ __init__()

def generic_task.InterruptableTask.__init__ (   self,
  name,
  runner,
  references,
  config,
  kwargs 
)

Create an Interruptable task.

Parameters
strname: unique task name
objectrunner: reference to the TaskRunner managing this task
dictreferences: a dictionary of all required modules
dictconfig: configuration dictionary

Member Function Documentation

◆ checkExtraPausePrerequisites()

def generic_task.InterruptableTask.checkExtraPausePrerequisites (   self)

If yout task has prerequisites for pausing, overwrite this function when subclassing and put the check here.

Returns
bool: return True if task can be paused right now, False otherwise

◆ checkExtraStartPrerequisites()

def generic_task.InterruptableTask.checkExtraStartPrerequisites (   self)

If your task has extra prerequisites that are not covered by checking if a certain task can be paused, overwrite this function when sub-classing.

Returns
bool: return True if task can be started, False otherwise

◆ checkPausePrerequisites()

def generic_task.InterruptableTask.checkPausePrerequisites (   self)

Check if task is allowed to pause based on external state.

◆ checkStartPrerequisites()

def generic_task.InterruptableTask.checkStartPrerequisites (   self)

Check whether this task can be started by checking if all tasks to be paused are either stopped or can be paused.

Also check custom prerequisites.

Returns
bool: True if task can be stated, False otherwise

◆ cleanupTask()

def generic_task.InterruptableTask.cleanupTask (   self)

If your task leaves behind any undesired state, take care to remove it in this function.

It is called after a task has finished.

◆ onchangestate()

def generic_task.InterruptableTask.onchangestate (   self,
  e 
)

Fysom callback for state transition.

Parameters
objecte: Fysom state transition description

◆ runTaskStep()

def generic_task.InterruptableTask.runTaskStep (   self)

Implement one work step of your task here.

Returns
bool: True if the task should continue running, False if it should finish.

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