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.

Example

See SleepWorker for an example of a Worker.

process()[source]

The expensive or blocking operation to process.

Attention

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.

Example

See Sleep for an example of a Thread.

__getattr__(item)[source]

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.

Parameters:
finished = None

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

is_finished()[source]

Whether the thread successfully finished.

Returns:boolTrue if the thread finished otherwise False.
is_running()[source]

Whether the thread is running.

Returns:boolTrue if the thread is running otherwise False.
quit()[source]

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.

stop(milliseconds=None)[source]

Calls quit() then wait().

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. 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.