Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix max_worker mismatch #79

Merged
merged 2 commits into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
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
16 changes: 8 additions & 8 deletions src/bfio/backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -596,8 +596,8 @@ def _read_image(self, X, Y, Z, C, T, output):

self.logger.debug("read_image(): _tile_indices = {}".format(self._tile_indices))

if self.frontend.max_workers > 1:
with ThreadPoolExecutor(self.frontend.max_workers) as executor:
if self.frontend._max_workers > 1:
with ThreadPoolExecutor(self.frontend._max_workers) as executor:
# cast to list so that any read errors are raised
list(
executor.map(
Expand Down Expand Up @@ -1155,8 +1155,8 @@ def _write_tiles(self, data, X, Y, Z, C, T):
def compress(page_index, tile_index, data, level=1):
return (page_index, tile_index, imagecodecs.deflate_encode(data, level))

if self.frontend.max_workers > 1:
with ThreadPoolExecutor(max_workers=self.frontend.max_workers) as executor:
if self.frontend._max_workers > 1:
with ThreadPoolExecutor(max_workers=self.frontend._max_workers) as executor:
compressed_tiles = []
for page_index, tileiter in tileiters:
for tileindex, tile in zip(tiles, tileiter):
Expand Down Expand Up @@ -1701,8 +1701,8 @@ def _process_chunk(self, dims):
] = data

def _read_image(self, X, Y, Z, C, T, output):
if self.frontend.max_workers > 1:
with ThreadPoolExecutor(self.frontend.max_workers) as executor:
if self.frontend._max_workers > 1:
with ThreadPoolExecutor(self.frontend._max_workers) as executor:
executor.map(self._process_chunk, self._tile_indices)
else:
for args in self._tile_indices:
Expand Down Expand Up @@ -1803,8 +1803,8 @@ def _process_chunk(self, dims):
)

def _write_image(self, X, Y, Z, C, T, image):
if self.frontend.max_workers > 1:
with ThreadPoolExecutor(self.frontend.max_workers) as executor:
if self.frontend._max_workers > 1:
with ThreadPoolExecutor(self.frontend._max_workers) as executor:
executor.map(self._process_chunk, self._tile_indices)
else:
for args in self._tile_indices:
Expand Down
2 changes: 1 addition & 1 deletion src/bfio/base_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def __init__(
file_path = Path(file_path)
self._file_path = file_path

self.max_workers = (
self._max_workers = (
max_workers
if max_workers is not None
else max([multiprocessing.cpu_count() // 2, 1])
Expand Down
12 changes: 6 additions & 6 deletions src/bfio/bfio.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def __init__(
"The max_workers keyword was present, but bioformats backend "
+ "only operates with a single worker. Setting max_workers=1."
)
self.max_workers = 1
self._max_workers = 1
except Exception as err:
if repr(err).split("(")[0] in [
"UnknownFormatException",
Expand All @@ -144,8 +144,8 @@ def __init__(
raise
elif self._backend_name == "zarr":
self._backend = backends.ZarrReader(self)
if self.max_workers == 2:
self.max_workers = 1
if self._max_workers == 2:
self._max_workers = 1
self.logger.debug(
"Setting max_workers to 1, since max_workers==2 runs slower."
+ "To change back, set the object property."
Expand Down Expand Up @@ -1035,7 +1035,7 @@ class if specified. *Defaults to None.*
"The max_workers keyword was present, but bioformats backend "
+ "only operates with a single worker. Setting max_workers=1."
)
self.max_workers = 1
self._max_workers = 1
except Exception as err:
if repr(err).split("(")[0] in [
"UnknownFormatException",
Expand All @@ -1053,8 +1053,8 @@ class if specified. *Defaults to None.*
raise
elif self._backend_name == "zarr":
self._backend = backends.ZarrWriter(self)
if self.max_workers == 2:
self.max_workers = 1
if self._max_workers == 2:
self._max_workers = 1
self.logger.debug(
"Setting max_workers to 1, since max_workers==2 runs slower."
+ "To change back, set the object property."
Expand Down
Loading