The backgroundjob module

Run jobs in the background using QThread.

class Job(parent=None)[source]

Bases: PyQt5.QtCore.QThread

A simple wrapper around QThread.

Before calling start() you should put the work function in the work attribute, and an optional finalize function (which will be called with the result) in the finalize attribute.

Or alternatively, inherit from this class and implement work() and finish() yourself. The result of the work function is stored in the result attribute.

finalize = None
running = False
done = False
result = None
start(self, priority: QThread.Priority = QThread.InheritPriority)[source]

Call the work function in the background thread.


Implement this to get the work done.

If you have long tasks you can Qt’s isInterruptionRequested() functionality.

Instead of implementing this method, you can put the work function in the work instance attribute.


This slot is called in the main thread when the work is done.

The default implementation calls the finalize function with the result.

class SingleRun[source]

Bases: object

Run a function in a background thread.

The outcome is silently discarded if another function is called before the old one finishes.


Forgets the running job.

The job is not terminated but the callback is not called.

run(func, callback=None)[source]

Run specified function in a background thread.

The thread is immediately started. If a callback is specified, it is called in the main thread with the result when the function is ready.