Read keeps the file and says its format; extract takes fields from columns; EEG batches carry their recording, on Dask where it is installed

This commit is contained in:
Roberto Treviño
2026-11-27 16:25:01 -06:00
parent 3546269eaf
commit 385cc5b80b
7 changed files with 103 additions and 28 deletions
+39
View File
@@ -0,0 +1,39 @@
"""Where long batches run (the EEG analysis, measuring a reference cohort). Where Dask is
installed (the `dask` extra, for testing on a cluster) they run on the scheduler at
DASK_SCHEDULER_ADDRESS, or on a Dask cluster of this machine's cores, through joblib's own
Dask backend. Without it (the product) joblib runs them on local processes. BATCH_JOBS caps
how many run at once (each task carries its recording: a cap paces a slow link)."""
import os
from collections.abc import Iterator
from contextlib import contextmanager
from importlib.util import find_spec
from joblib import parallel_config
from joblib.externals.loky import get_reusable_executor
def jobs() -> int:
"""How many tasks run at once: BATCH_JOBS, or every core (or worker)."""
return int(os.environ.get("BATCH_JOBS", "-1"))
@contextmanager
def batch() -> Iterator[None]:
if find_spec("distributed") is None:
try:
yield
finally: # the local workers go when the batch is done
get_reusable_executor().shutdown(wait=True)
return
from distributed import Client, LocalCluster
address = os.environ.get("DASK_SCHEDULER_ADDRESS")
# one process per core, no dashboard port to collide with (8787 is often taken)
where = address or LocalCluster(threads_per_worker=1, dashboard_address=None)
try:
with Client(where), parallel_config(backend="dask"):
yield
finally:
if not address:
where.close()