Package moul :: Package qt :: Module threadlet :: Class Threadlet
[hide private]
[frames] | no frames]

Class Threadlet



      object --+            
               |            
     sip.wrapper --+        
                   |        
PyQt4.QtCore.QObject --+    
                       |    
    PyQt4.QtCore.QThread --+
                           |
                          Threadlet
Known Subclasses:
YieldingThreadlet

Threadlet - execute a function in a seperate thread

Use this class to run a CPU or I/O bound function in a seperate thread.
>>> def pow(x, y): return x**y
>>> def printer(r): print r
>>> parent.example = Threadlet()
>>> parent.connect(parent.example, SIGNAL('done(result)'), printer)
>>> parent.example.detach(pow, 2, 6)
Signals emitted: You should disconnect all signals after the threadlet has finished >>> parent.disconnect(parent.example, SIGNAL('done(result)')) >>> del parent.example


Emits Qt Signal (finished()): Signal is emitted when the thread has finished.

Emits Qt Signal (terminated()): Signal is emitted when the thread is terminated.

Emits Qt Signal (started()): Signal is emitted when the thread starts executing.

Warning: The function and all applied arguments must be thread safe!

Nested Classes [hide private]

Inherited from PyQt4.QtCore.QThread: Priority


Instance Methods [hide private]
  __init__(self, parent=None)
Constructor
  clear(self)
Clear variables
  detach(self, obj, *args, **kwargs)
Detach a function call
  run(self)
Payload - runs the callable and emits done(result)

Inherited from PyQt4.QtCore.QThread: childEvent, connectNotify, currentThread, currentThreadId, customEvent, disconnectNotify, exec_, exit, isFinished, isRunning, msleep, priority, quit, receivers, sender, setPriority, setStackSize, setTerminationEnabled, sleep, stackSize, start, terminate, timerEvent, usleep, wait

Inherited from PyQt4.QtCore.QObject: blockSignals, children, connect, deleteLater, disconnect, dumpObjectInfo, dumpObjectTree, dynamicPropertyNames, emit, event, eventFilter, findChild, findChildren, inherits, installEventFilter, isWidgetType, killTimer, metaObject, moveToThread, objectName, parent, property, removeEventFilter, setObjectName, setParent, setProperty, signalsBlocked, startTimer, thread, tr, trUtf8

Inherited from sip.wrapper: __delattr__, __getattribute__, __new__, __setattr__

Inherited from object: __hash__, __repr__, __str__


Class Variables [hide private]

Inherited from PyQt4.QtCore.QThread: HighPriority, HighestPriority, IdlePriority, InheritPriority, LowPriority, LowestPriority, NormalPriority, TimeCriticalPriority

Inherited from PyQt4.QtCore.QObject: __reduce__, __reduce_ex__


Properties [hide private]

Inherited from object: __class__


Method Details [hide private]

__init__(self, parent=None)
(Constructor)

 
Constructor
Parameters:
  • parent (QObject instance or None) - Qt parent object
Overrides: sip.wrapper.__init__

clear(self)

 

Clear variables

Mutex must be locked before clear() is called from a method!

detach(self, obj, *args, **kwargs)

 
Detach a function call
Parameters:
  • obj - a callable (or iterable for YieldingThreadlet)
  • *args - additional arguments for the function
  • **kwargs - additional keyword arguments for the function

run(self)

 

Payload - runs the callable and emits done(result)

The function and its args/kwargs are cleared after the function has run to avoid cyclic references.
Overrides: PyQt4.QtCore.QThread.run

Emits Qt Signal (done(result)): Signal is emitted when the function has returned.