def __init__(self, capacity):
if not isinstance(capacity, int):
raise TypeError("capacity must be an integer")
if capacity < 1:
raise ValueError("capacity must be >= 1")
# Invariants:
# get_semaphore.value() == len(self._data)
# put_semaphore.value() + get_semaphore.value() = capacity
self.capacity = operator.index(capacity)
self._put_semaphore = Semaphore(capacity, max_value=capacity)
self._get_semaphore = Semaphore(0, max_value=capacity)
self._data = deque()
self._join_lot = _core.ParkingLot()
self._unprocessed = 0
评论列表
文章目录