Skip to content

Commit c16e686

Browse files
Feat: Improve the ways dask can be configured
1 parent 4271c5b commit c16e686

File tree

2 files changed

+17
-10
lines changed

2 files changed

+17
-10
lines changed

bluepyparallel/parallel.py

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import os
66
from abc import abstractmethod
77
from collections.abc import Iterator
8-
from copy import deepcopy
98
from functools import partial
109
from multiprocessing.pool import Pool
1110

@@ -214,7 +213,6 @@ def shutdown(self):
214213

215214

216215
_DEFAULT_DASK_CONFIG = {
217-
"temporary-directory": None,
218216
"distributed": {
219217
"worker": {
220218
"use_file_locking": False,
@@ -242,9 +240,9 @@ def shutdown(self):
242240
Another way is to create a YAML file containing the configuration and then set the `DASK_CONFIG`
243241
environment variable to its path. Note that this environment variable must be set before `dask`
244242
is imported and can not be updated afterwards.
245-
Also, it is possible to use the `TMPDIR` environment variable to specify the directory in which
246-
the dask internals will be created. Note that this value will be overridden if a dask configuration
247-
is given.
243+
Also, it is possible to use the `SHMDIR` or the `TMPDIR` environment variable to specify the
244+
directory in which the dask internals will be created. Note that this value will be overridden if a
245+
dask configuration is given.
248246
If no config is provided, the following is used:
249247
250248
.. code-block:: JSON
@@ -279,11 +277,20 @@ def __init__(
279277
**kwargs,
280278
):
281279
"""Initialize the dask factory."""
282-
_default_config = deepcopy(_DEFAULT_DASK_CONFIG)
283-
_default_config["temporary-directory"] = os.environ.get("TMPDIR", None)
284-
dask.config.update_defaults(_default_config)
280+
# Merge the default config with the existing config (keep existing values)
281+
new_dask_config = dask.config.merge(_DEFAULT_DASK_CONFIG, dask.config.config)
282+
283+
# Get temporary-directory from environment variables
284+
_TMP = os.environ.get("SHMDIR", None) or os.environ.get("TMPDIR", None)
285+
if _TMP is not None: # pragma: no cover
286+
new_dask_config["temporary-directory"] = _TMP
287+
288+
# Merge the config with the one given as argument
285289
if dask_config is not None: # pragma: no cover
286-
dask.config.set(dask_config)
290+
new_dask_config = dask.config.merge(new_dask_config, dask_config)
291+
292+
# Set the dask config
293+
dask.config.set(new_dask_config)
287294

288295
dask_scheduler_path = scheduler_file or os.getenv(self._SCHEDULER_PATH)
289296
self.interactive = True

bluepyparallel/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
"""Version of the bluepyparallel package."""
22

3-
VERSION = "0.1.0" # pragma: no cover
3+
VERSION = "0.1.1.dev0" # pragma: no cover

0 commit comments

Comments
 (0)