Skip to content

Commit eb3b35d

Browse files
authored
get num cpus at function runtime (#471)
1 parent f63bb8a commit eb3b35d

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

src/mdio/segy/blocked_io.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
zfpy = None
3939

4040
default_cpus = cpu_count(logical=True)
41-
NUM_CPUS = int(os.getenv("MDIO__IMPORT__CPU_COUNT", default_cpus))
4241

4342

4443
def to_zarr(
@@ -119,7 +118,8 @@ def to_zarr(
119118
# For Unix async writes with s3fs/fsspec & multiprocessing,
120119
# use 'spawn' instead of default 'fork' to avoid deadlocks
121120
# on cloud stores. Slower but necessary. Default on Windows.
122-
num_workers = min(num_chunks, NUM_CPUS)
121+
num_cpus = int(os.getenv("MDIO__IMPORT__CPU_COUNT", default_cpus))
122+
num_workers = min(num_chunks, num_cpus)
123123
context = mp.get_context("spawn")
124124
executor = ProcessPoolExecutor(max_workers=num_workers, mp_context=context)
125125

src/mdio/segy/parsers.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
from segy import SegyFile
2222

2323
default_cpus = cpu_count(logical=True)
24-
NUM_CPUS = int(os.getenv("MDIO__IMPORT__CPU_COUNT", default_cpus))
2524

2625

2726
def parse_index_headers(
@@ -54,7 +53,8 @@ def parse_index_headers(
5453
# For Unix async reads with s3fs/fsspec & multiprocessing,
5554
# use 'spawn' instead of default 'fork' to avoid deadlocks
5655
# on cloud stores. Slower but necessary. Default on Windows.
57-
num_workers = min(n_blocks, NUM_CPUS)
56+
num_cpus = int(os.getenv("MDIO__IMPORT__CPU_COUNT", default_cpus))
57+
num_workers = min(n_blocks, num_cpus)
5858
context = mp.get_context("spawn")
5959

6060
tqdm_kw = dict(unit="block", dynamic_ncols=True)

0 commit comments

Comments
 (0)