Skip to content
This repository has been archived by the owner on Feb 9, 2024. It is now read-only.

Commit

Permalink
Limit number of processes on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
adamltyson committed Oct 10, 2023
1 parent 7a763f0 commit 863df95
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion imio/load.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import logging
import math
import os
import platform
import warnings
from concurrent.futures import ProcessPoolExecutor

Expand Down Expand Up @@ -357,6 +358,7 @@ def threaded_load_from_sequence(
y_scaling_factor=1.0,
anti_aliasing=True,
n_free_cpus=2,
n_max_processes=None,
):
"""
Use multiprocessing to load a brain from a sequence of image paths.
Expand All @@ -371,12 +373,20 @@ def threaded_load_from_sequence(
the image prior to down-scaling. It is crucial to filter when
down-sampling the image to avoid aliasing artifacts.
:param int n_free_cpus: Number of cpu cores to leave free.
:param int n_max_processes: Maximum number of processes
:return: The loaded and scaled brain
:rtype: np.ndarray
"""

stacks = []
n_processes = get_num_processes(min_free_cpu_cores=n_free_cpus)
# On Windows, max_workers must be less than or equal to 61
# https://docs.python.org/3/library/concurrent.futures.html#processpoolexecutor
if platform.system() == "Windows":
n_max_processes = 61

Check warning on line 385 in imio/load.py

View check run for this annotation

Codecov / codecov/patch

imio/load.py#L384-L385

Added lines #L384 - L385 were not covered by tests

n_processes = get_num_processes(

Check warning on line 387 in imio/load.py

View check run for this annotation

Codecov / codecov/patch

imio/load.py#L387

Added line #L387 was not covered by tests
min_free_cpu_cores=n_free_cpus, n_max_processes=n_max_processes
)

# WARNING: will not work with interactive interpreter.
pool = ProcessPoolExecutor(max_workers=n_processes)
Expand Down

0 comments on commit 863df95

Please sign in to comment.