Expanded scope of thread lock in screen::grab() method.
This commit is contained in:
+6
-7
@@ -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(?)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user