class CustomThread(QtCore.QThread):

    def __init__(self, target, slotOnFinished=None):
        super(CustomThread, self).__init__()
self.target = target
if slotOnFinished:
    self.finished.connect(slotOnFinished)

def run(self, *args, **kwargs):
    self.target(*args, **kwargs)
Start a new thread in Python with a callback method in Main Thread for PyQT application