mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-02-05 18:55:23 +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(
|
self.size = multiprocessing.RawValue(
|
||||||
ctypes.c_int, 0
|
ctypes.c_int, 0
|
||||||
) # Add a counter for the number of items in the queue
|
) # 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):
|
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 self.maxsize > 0 and self.size.value >= self.maxsize:
|
||||||
if block:
|
if block:
|
||||||
start_time = time.time()
|
start_time = time.time()
|
||||||
@ -1318,7 +1316,6 @@ class LimitedQueue(FFQueue):
|
|||||||
return super().put(x, block=block, timeout=timeout)
|
return super().put(x, block=block, timeout=timeout)
|
||||||
|
|
||||||
def get(self, block=True, timeout=DEFAULT_TIMEOUT):
|
def get(self, block=True, timeout=DEFAULT_TIMEOUT):
|
||||||
with self.lock: # Acquire the lock
|
|
||||||
if self.size.value <= 0 and not block:
|
if self.size.value <= 0 and not block:
|
||||||
raise Empty
|
raise Empty
|
||||||
self.size.value -= 1
|
self.size.value -= 1
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user