def __init__(self, maximum, parent=None): QThread.__init__(self, parent) self.maximum = maximum # this semaphore is used to stop the thread from outside. As long # as the thread is permitted to run, it has yet a single resource # available. If the thread is stopped, this resource is acquired, # and the thread breaks its counting loop at the next iteration. self._run_semaphore = QSemaphore(1)