TaurusEmitterThread

Inheritance diagram of TaurusEmitterThread
class TaurusEmitterThread(parent=None, name='', queue=None, method=None, cursor=None, sleep=5000, polling=0, loopwait=5)[source]

Bases: PyQt5.QtCore.QThread

This object get items from a python Queue and performs a thread safe operation on them. It is useful to serialize Qt tasks in a background thread.

Parameters
  • parent – a Qt/Taurus object

  • name – identifies object logs

  • queue – if None parent.getQueue() is used, if not then the queue passed as argument is used

  • method – the method to be executed using each queue item as argument

  • cursor – if True or QCursor a custom cursor is set while the Queue is not empty

How TaurusEmitterThread works:

TaurusEmitterThread is a worker thread that processes a queue of iterables passed as arguments to the specified method every time that doSomething() is called:

  • self.method(*item) will be called if TaurusEmitterThread.method

    has been initialized.

  • item[0](item[1:]) will be called if method is not initialized

    and the first element of the queued iterable is callable.

TaurusEmitterThread uses two queues:

  • self.queue manages the objects added externally:

  • the next() method passes objects from self.queue to self.todo queue

  • every time that a somethingDone signal arrives next() is called.

  • next() can be called also externally to ensure that the main queue is being processed.

  • the queue can be accessed externally using getQueue()

  • getQueue().qsize() returns number of remaining objects in queue.

  • while there are objects in queue the .next() method will override applications cursor. a call to next() with an empty queue will restore the original cursor.

  • self.todo is managed by the run()/start() method:

  • a loop waits continuously for new objects in self.todo queue.

  • if an object is found, it is sent in a doSomething signal.

  • if “exit” is found the loop exits.

Usage example:

#Applying TaurusEmitterThread to an existing class:
from queue import Queue
from functools import partial

def modelSetter(args):
    obj,model = args[0],args[1]
    obj.setModel(model)

klass TaurusGrid(Qt.QFrame, TaurusBaseWidget):
    ...
    def __init__(self, parent = None, designMode = False):
        ...
        self.modelsQueue = Queue()
        self.modelsThread = TaurusEmitterThread(parent=self,
                queue=self.modelsQueue,method=modelSetter )
        ...
    def build_widgets(...):
        ...
                    previous,synoptic_value =                                 synoptic_value,TaurusValue(cell_frame)
                    #synoptic_value.setModel(model)
                    self.modelsQueue.put((synoptic_value,model))
        ...
    def setModel(self,model):
        ...
        if hasattr(self,'modelsThread') and                         not self.modelsThread.isRunning():
            self.modelsThread.start()
        elif self.modelsQueue.qsize():
            self.modelsThread.next()
        ...
clear()[source]
getDone()[source]

Returns % of done tasks in 0-1 range

getQueue()[source]
next()[source]
onRefresh()[source]
purge(obj)[source]

Remove a given object from all queues

run(self)[source]