Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions python/ndstorage/ndtiff_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ def __init__(self, dataset_path=None, file_io: NDTiffFileIO = BUILTIN_FILE_IO, s

self.file_io = file_io
self._lock = threading.RLock()
self._put_image_lock = threading.Lock()
if writable:
self.major_version = MAJOR_VERSION
self.minor_version = MINOR_VERSION
Expand Down Expand Up @@ -166,6 +167,8 @@ def read_metadata(self, channel=None, z=None, time=None, position=None, row=None
return self._do_read_metadata(axes)

def put_image(self, coordinates, image, metadata):
# wait for put_image to finish before calling it again.
self._put_image_lock.acquire()
if not self._writable:
raise RuntimeError("Cannot write to a read-only dataset")

Expand Down Expand Up @@ -203,6 +206,7 @@ def put_image(self, coordinates, image, metadata):
self._index_file.write(index_data_entry.as_byte_buffer().getvalue())
# remove from pending images
del self._write_pending_images[frozenset(coordinates.items())]
self._put_image_lock.release()

def finish(self):
if self.current_writer is not None:
Expand Down
Loading