Skip to content

Semaphore

Base classes

Name Children Inherits
QSemaphore
PySide6.QtCore
QSemaphore(self, /, n: int | None \= None) -> None

⋔ Inheritance diagram

graph TD
  1528490909["core.Semaphore"]
  1212089094["QtCore.QSemaphore"]
  37984305["Shiboken.Object"]
  2751680898["builtins.object"]
  1212089094 --> 1528490909
  37984305 --> 1212089094
  2751680898 --> 37984305

🛈 DocStrings

Bases: QSemaphore

General counting semaphore.

Source code in prettyqt/core/semaphore.py
class Semaphore(QtCore.QSemaphore):
    """General counting semaphore."""

    @contextlib.contextmanager
    def acquire_resources(self, n: int = 1) -> Generator[bool]:
        acquired = self.tryAcquire(n)
        try:
            yield acquired
        finally:
            if acquired:
                self.release(n)

:fa-brands-github: Show source on GitHub