msl.qt.threading module¶
Base classes for starting a process in a new QThread.
- class msl.qt.threading.Worker(*args, **kwargs)[source]¶
Bases:
QObjectProcess an expensive or blocking operation in a thread that is separate from the main thread.
You can access to the attributes of the
Workeras though they are attributes of theThread.The
*argsand**kwargsparameters are passed to the constructor of theWorkerwhen thestart()method is called.Example
See
SleepWorkerfor an example of aWorker.
- class msl.qt.threading.Thread(worker)[source]¶
Bases:
QObjectMoves a
Workerto a newQThread.- Parameters:
worker – A
Workersubclass that has not been instantiated.
Example
See
Sleepfor an example of aThread.- error_handler(exception, traceback)[source]¶
If an exception is raised by the
Workerthen 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
Workerin aQThread.The
*argsand**kwargsare passed to the constructor of theWorkerclass.
- 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. IfNonethen this method will never time out and the thread must return from its run method.- Returns:
boolorNone–Trueif the thread finished,Falseif the thread timed out orNoneif the thread is not running.
- worker_connect(signal, slot)[source]¶
Connect a
Signalfrom theWorkerto 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
Workeras though they are attributes of theThread.
- worker_disconnect(signal, slot)[source]¶
Disconnect a
Slotfrom aSignalof 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
Workeras though they are attributes of theThread.- Parameters:
signal (
str,SignalorSignalInstance) – 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().