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

Limit number of processes on Windows #47

Closed
wants to merge 1 commit into from
Closed
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
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

n_processes = get_num_processes(
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