Expanded scope of thread lock in screen::grab() method.

This commit is contained in:
Randi
2024-06-13 19:59:35 -04:00
parent 7141e671d1
commit 4199705fe8
+6 -7
View File
@@ -73,15 +73,14 @@ def grab(force_new: bool = False) -> np.ndarray:
global cached_img
global last_grab
# with 25fps we have 40ms per frame. If we check for 20ms range to make sure we can still get each frame if we want.
if not force_new and cached_img is not None and last_grab is not None and time.perf_counter() - last_grab < 0.04:
return cached_img
else:
with cached_img_lock:
with cached_img_lock:
if not force_new and cached_img is not None and last_grab is not None and time.perf_counter() - last_grab < 0.04:
return cached_img
else:
last_grab = time.perf_counter()
img = np.array(sct.grab(monitor_roi))
with cached_img_lock:
img = np.array(sct.grab(monitor_roi))
cached_img = img[:, :, :3]
return cached_img
return cached_img
# TODO: Move the below funcs to utils(?)