QSemaphoreLocker

Methods

qconcurrency.threading_.QSemaphoreLocker.__init__(…)
param semaphore:
 The semaphore that you’d like to lock
qconcurrency.threading_.QSemaphoreLocker.staticMetaObject

Documentation

class qconcurrency.threading_.QSemaphoreLocker(semaphore, n=1, timeout=-1)[source]

Bases: PySide.QtCore.QObject

Mirrors the behaviour of QtCore.QMutexLocker, but instead of a mutex manages a QtCore.QSemaphore .

Example

class MyClass( QtCore.QObject ):
    def __init__(self):
        self._semaphore = QtCore.QSemaphore(5)

    def load(self):
        locked = QSemaphoreLocker( self._semaphore, 3, 500 )

        # ...
        # when locked goes out of scope, 3x resource is released
        # ...

    def load_again(self):

        with QSemaphoreLocker( self._semaphore ):
            # ...
            # do these actions while 1x semaphore is locked
            # ...

        # .. semaphore resources no longer in use ..
__init__(semaphore, n=1, timeout=-1)[source]
Parameters:
  • semaphore (QtCore.QSemaphore) – The semaphore that you’d like to lock
  • n (int, optional) – The number of resources you would like to lock in the semaphore.
  • timeout (int, optional) – milliseconds you would like to wait for n resources to become available before failing QtCore.QSemaphore.acquire() A RuntimeError will be raised.
staticMetaObject = <PySide.QtCore.QMetaObject object>