Skip to content

Commit 34c54b9

Browse files
author
Marius Causemann
committed
disable multithreading for surface extraction on windowns
1 parent 85448d8 commit 34c54b9

File tree

1 file changed

+20
-12
lines changed

1 file changed

+20
-12
lines changed

workflow/scripts/extract_surfaces.py

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
from pathlib import Path
88
from utils import get_bounding_box
99
import fastremap
10+
import sys
11+
import shutil
12+
import itertools
1013

1114
from pyvista.core import _vtk_core as _vtk
1215
from pyvista.core.filters import _get_output, _update_alg
@@ -126,19 +129,24 @@ def extract_cell_meshes(
126129
global grid
127130
padded = np.pad(img, 1)
128131
grid = pv.ImageData(dimensions=padded.shape, spacing=resolution, origin=(0, 0, 0))
129-
os.system(f"rm -rf {write_dir}/*")
130-
os.system(f"mkdir -p {write_dir}")
131-
import multiprocessing
132-
from multiprocessing import Pool
133-
try:
134-
multiprocessing.set_start_method("fork") # wont work on windows
135-
except ValueError: pass
136-
with Pool(ncpus) as pool:
137-
args = [(obj_id, mesh_reduction_factor, taubin_smooth_iter,
132+
133+
write_path = Path(write_dir)
134+
if write_path.exists():
135+
shutil.rmtree(write_path)
136+
write_path.mkdir(parents=True, exist_ok=True)
137+
138+
args = [(obj_id, mesh_reduction_factor, taubin_smooth_iter,
138139
f"{write_dir}/{obj_id}.ply") for obj_id in cell_labels]
139-
surfaces = pool.starmap(extract_surf_id, args)
140-
pool.close()
141-
pool.join()
140+
141+
if sys.platform != "win32":
142+
import multiprocessing
143+
multiprocessing.set_start_method("fork")
144+
with multiprocessing.Pool(ncpus) as pool:
145+
surfaces = pool.starmap(extract_surf_id, args)
146+
pool.close()
147+
pool.join()
148+
else:
149+
surfaces = list(itertools.starmap(extract_surf_id, args))
142150
return surfaces
143151

144152
def create_balanced_csg_tree(surface_files):

0 commit comments

Comments
 (0)