msl.qt.threading module¶
Base classes for starting a process in a new QThread
.
- class msl.qt.threading.Worker(*args, **kwargs)[source]¶
Bases:
QObject
Process an expensive or blocking operation in a thread that is separate from the main thread.
You can access to the attributes of the
Worker
as though they are attributes of theThread
.The
*args
and**kwargs
parameters are passed to the constructor of theWorker
when thestart()
method is called.Example
See
SleepWorker
for an example of aWorker
.
- class msl.qt.threading.Thread(worker)[source]¶
Bases:
QObject
Moves a
Worker
to a newQThread
.- Parameters:
worker – A
Worker
subclass that has not been instantiated.
Example
See
Sleep
for an example of aThread
.- error_handler(exception, traceback)[source]¶
If an exception is raised by the
Worker
then the default behaviour is to show the error message in acritical()
dialog window.You can override this method to implement your own error handler.
- Parameters:
exception (
BaseException
) – The exception instancetraceback (
traceback
) – A traceback object.
- start(*args, **kwargs)[source]¶
Start processing the
Worker
in aQThread
.The
*args
and**kwargs
are passed to the constructor of theWorker
class.
- wait(milliseconds=None)[source]¶
Wait for the thread to either finish or timeout.
- Parameters:
milliseconds (
int
, optional) – The number of milliseconds to wait before a timeout occurs. IfNone
then this method will never time out and the thread must return from its run method.- Returns:
bool
orNone
–True
if the thread finished,False
if the thread timed out orNone
if the thread is not running.
- worker_connect(signal, slot)[source]¶
Connect a
Signal
from theWorker
to aSlot
.This method is intended to be called before a worker thread starts. Although, you can still call this method when a worker thread is running, it is easier (fewer characters to type) to access the attributes of a
Worker
as though they are attributes of theThread
.
- worker_disconnect(signal, slot)[source]¶
Disconnect a
Slot
from aSignal
of theWorker
.This method is intended to be called before a worker thread is restarted. Although, you can still call this method when a worker thread is running, it is easier (fewer characters to type) to access the attributes of a
Worker
as though they are attributes of theThread
.- Parameters:
signal (
str
,Signal
orSignalInstance
) – The signal to disconnect the slot from. Must be the same value that was used inworker_connect()
.slot – Must be the same callable that was used in
worker_connect()
.