diff --git a/picamera2/picamera2.py b/picamera2/picamera2.py index 5827f75d..903372bc 100644 --- a/picamera2/picamera2.py +++ b/picamera2/picamera2.py @@ -237,6 +237,7 @@ def __init__(self, camera_num=0, verbose_console=None, tuning=None): self.notifymeread = os.fdopen(self.notifyme_r, 'rb') self._cm.add(camera_num, self) self.camera_idx = camera_num + self.request_lock = threading.Lock() # global lock used by requests self._requestslock = threading.Lock() self._requests = [] if verbose_console is None: diff --git a/picamera2/request.py b/picamera2/request.py index a54e12af..12c7e213 100644 --- a/picamera2/request.py +++ b/picamera2/request.py @@ -1,6 +1,5 @@ import io import logging -import threading import time from datetime import datetime from pathlib import Path @@ -102,15 +101,17 @@ class CompletedRequest: def __init__(self, request, picam2): self.request = request self.ref_count = 1 - self.lock = threading.Lock() + self.lock = picam2.request_lock self.picam2 = picam2 self.stop_count = picam2.stop_count self.configure_count = picam2.configure_count self.config = self.picam2.camera_config.copy() self.stream_map = self.picam2.stream_map.copy() - self.syncs = [picam2.allocator.sync(self.picam2.allocator, buffer, False) for buffer in self.request.buffers.values()] - self.picam2.allocator.acquire(self.request.buffers) - [sync.__enter__() for sync in self.syncs] + with self.lock: + self.syncs = [picam2.allocator.sync(self.picam2.allocator, buffer, False) + for buffer in self.request.buffers.values()] + self.picam2.allocator.acquire(self.request.buffers) + [sync.__enter__() for sync in self.syncs] def acquire(self): """Acquire a reference to this completed request, which stops it being recycled back to the camera system."""