mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-02-05 10:45:21 +03:00
Refactor put and get methods in LimitedQueue to handle queue size and blocking behavior more efficiently
This commit is contained in:
parent
4e2a529b0e
commit
b682d835d0
@ -1300,10 +1300,8 @@ class LimitedQueue(FFQueue):
|
||||
self.size = multiprocessing.RawValue(
|
||||
ctypes.c_int, 0
|
||||
) # Add a counter for the number of items in the queue
|
||||
self.lock = multiprocessing.Lock() # Add a lock
|
||||
|
||||
def put(self, x, block=True, timeout=DEFAULT_TIMEOUT):
|
||||
with self.lock: # Acquire the lock
|
||||
if self.maxsize > 0 and self.size.value >= self.maxsize:
|
||||
if block:
|
||||
start_time = time.time()
|
||||
@ -1318,7 +1316,6 @@ class LimitedQueue(FFQueue):
|
||||
return super().put(x, block=block, timeout=timeout)
|
||||
|
||||
def get(self, block=True, timeout=DEFAULT_TIMEOUT):
|
||||
with self.lock: # Acquire the lock
|
||||
if self.size.value <= 0 and not block:
|
||||
raise Empty
|
||||
self.size.value -= 1
|
||||
|
||||
Loading…
Reference in New Issue
Block a user