msl.qt.threading module

Base classes for starting a process in a new QThread.

msl.qt.threading.Signal(*args, **kwargs)
class msl.qt.threading.Worker[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 the Thread.


See SleepWorker for an example of a Worker.


The expensive or blocking operation to process.


You must override this method.

class msl.qt.threading.Thread(worker)[source]

Bases: QObject

Moves the worker to a new QtCore.QThread.

Parameters:worker – A Worker subclass that has NOT been instantiated.


See Sleep for an example of a Thread.


All other attributes are assumed to be those of the Worker.

error_handler(exception, traceback)[source]

If an exception is raised by the Worker then the default behaviour is to show the error message in a critical() dialog window.

You can override this method to implement your own error handler.

finished = None

This Signal is emitted when the thread finishes (i.e., when Worker.process() finishes).


Whether the thread successfully finished.

Returns:boolTrue if the thread finished otherwise False.

Whether the thread is running.

Returns:boolTrue if the thread is running otherwise False.

Tells the thread’s event loop to exit.

start(*args, **kwargs)[source]

Start processing the Worker in a QtCore.QThread.

The *args and **kwargs are passed to the constructor of the Worker class.


Calls quit() then wait().


Wait for the thread to either finish or timeout.

Parameters:milliseconds (int, optional) – The number of milliseconds to wait before a timeout occurs. If None then this method will never timeout and the thread must return from its run method.
Returns:bool or NoneTrue if the thread finished, False if the thread timed out or None if the thread is not running.