|
5 | 5 | import os |
6 | 6 | from abc import abstractmethod |
7 | 7 | from collections.abc import Iterator |
8 | | -from copy import deepcopy |
9 | 8 | from functools import partial |
10 | 9 | from multiprocessing.pool import Pool |
11 | 10 |
|
@@ -214,7 +213,6 @@ def shutdown(self): |
214 | 213 |
|
215 | 214 |
|
216 | 215 | _DEFAULT_DASK_CONFIG = { |
217 | | - "temporary-directory": None, |
218 | 216 | "distributed": { |
219 | 217 | "worker": { |
220 | 218 | "use_file_locking": False, |
@@ -242,9 +240,9 @@ def shutdown(self): |
242 | 240 | Another way is to create a YAML file containing the configuration and then set the `DASK_CONFIG` |
243 | 241 | environment variable to its path. Note that this environment variable must be set before `dask` |
244 | 242 | 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. |
248 | 246 | If no config is provided, the following is used: |
249 | 247 |
|
250 | 248 | .. code-block:: JSON |
@@ -279,11 +277,20 @@ def __init__( |
279 | 277 | **kwargs, |
280 | 278 | ): |
281 | 279 | """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 |
285 | 289 | 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) |
287 | 294 |
|
288 | 295 | dask_scheduler_path = scheduler_file or os.getenv(self._SCHEDULER_PATH) |
289 | 296 | self.interactive = True |
|
0 commit comments