- warn instead of raise error when file is empty upon closing
This commit is contained in:
2
setup.py
2
setup.py
@@ -5,7 +5,7 @@ with open('README.md', 'r') as fh:
|
|||||||
|
|
||||||
setuptools.setup(
|
setuptools.setup(
|
||||||
name='tiffwrite',
|
name='tiffwrite',
|
||||||
version='2022.5.4',
|
version='2022.6.0',
|
||||||
author='Wim Pomp @ Lenstra lab NKI',
|
author='Wim Pomp @ Lenstra lab NKI',
|
||||||
author_email='w.pomp@nki.nl',
|
author_email='w.pomp@nki.nl',
|
||||||
description='Parallel tiff writer compatible with ImageJ.',
|
description='Parallel tiff writer compatible with ImageJ.',
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import os
|
||||||
import tifffile
|
import tifffile
|
||||||
import colorcet
|
import colorcet
|
||||||
import struct
|
import struct
|
||||||
@@ -485,10 +486,14 @@ class IJTiffFile:
|
|||||||
dtype=int).T.flatten()]) for color in self.colors]
|
dtype=int).T.flatten()]) for color in self.colors]
|
||||||
|
|
||||||
def close(self):
|
def close(self):
|
||||||
assert len(self.frames_added) >= 1, 'at least one frame should be added to the tiff'
|
|
||||||
if multiprocessing.current_process().pid == self.main_pid:
|
if multiprocessing.current_process().pid == self.main_pid:
|
||||||
self.pool_manager.close(self)
|
self.pool_manager.close(self)
|
||||||
with self.fh.lock() as fh:
|
with self.fh.lock() as fh:
|
||||||
|
if len(self.frames_added) == 0:
|
||||||
|
warn('At least one frame should be added to the tiff, removing file.')
|
||||||
|
fh.close()
|
||||||
|
os.remove(self.path)
|
||||||
|
else:
|
||||||
if len(self.frames_written) < np.prod(self.shape): # add empty frames if needed
|
if len(self.frames_written) < np.prod(self.shape): # add empty frames if needed
|
||||||
for n in product(*[range(i) for i in self.shape]):
|
for n in product(*[range(i) for i in self.shape]):
|
||||||
if n not in self.frames_written:
|
if n not in self.frames_written:
|
||||||
@@ -598,6 +603,7 @@ class PoolManager:
|
|||||||
self.tifs.pop(tif.path)
|
self.tifs.pop(tif.path)
|
||||||
if not self.tifs:
|
if not self.tifs:
|
||||||
self.__class__.instance = None
|
self.__class__.instance = None
|
||||||
|
if self.is_alive:
|
||||||
self.is_alive = False
|
self.is_alive = False
|
||||||
self.done.set()
|
self.done.set()
|
||||||
while not self.queue.empty():
|
while not self.queue.empty():
|
||||||
|
|||||||
Reference in New Issue
Block a user