On this page
  1. threading.BoundedSemaphore
  2. Import
  3. Signature & Overview
  4. Methods & Attributes
  5. Usage
  6. Gotchas
  7. REPL Inspect

threading.BoundedSemaphore

Prev: threading.Barrier | Up: threading | Next: threading.BrokenBarrierError
Rel: threading.active_count, threading.Barrier, threading.BrokenBarrierError, threading.Condition
Ref: docs.python.org — threading.BoundedSemaphore
Tags: #public #python3 #stdlib #threading


Import

import threading
from threading import BoundedSemaphore

Signature & Overview

threading.BoundedSemaphore(value=1)

Implements a bounded semaphore.

Methods & Attributes

Usage

import threading

sem = threading.BoundedSemaphore(2)
with sem:
    assert True
try:
    sem.release()   # releasing above initial value raises ValueError
    assert False
except ValueError:
    assert True

Gotchas

REPL Inspect

from threading import BoundedSemaphore
help(BoundedSemaphore)

Linked from

Related notes