QSemaphoreLocker¶
Methods¶
qconcurrency.threading_.QSemaphoreLocker.__init__(…) |
|
||||
qconcurrency.threading_.QSemaphoreLocker.staticMetaObject |
|||||
Documentation¶
-
class
qconcurrency.threading_.QSemaphoreLocker(semaphore, n=1, timeout=-1)[source]¶ Bases:
PySide.QtCore.QObjectMirrors the behaviour of
QtCore.QMutexLocker, but instead of a mutex manages aQtCore.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()ARuntimeErrorwill be raised.
-
staticMetaObject= <PySide.QtCore.QMetaObject object>¶
-