Skip to content

Commit e656c2d

Browse files
committed
Set dask to single-threaded mode in tests
Temporary work around for a segfault most likely related to installs of netCDF4 1.7.1 from PyPI #139
1 parent 2ea6c30 commit e656c2d

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

tests/conftest.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,18 @@
1+
"""
2+
emsarray test suite.
3+
4+
.. option --dask-scheduler <scheduler>
5+
6+
Set the scheduler for dask.
7+
Currently the test suite segfaults when the default scheduler is used.
8+
The scheduler is overridden to be 'synchronous', which avoids this issue.
9+
Use this flag to choose a different scheduler for testing fixes to the segfault.
10+
"""
111
import logging
212
import pathlib
313
from unittest import mock
414

15+
import dask
516
import pytest
617

718
import emsarray
@@ -20,6 +31,39 @@ def pytest_runtest_setup(item):
2031
item.fixturenames.append("matplotlib_backend")
2132

2233

34+
def pytest_addoption(parser):
35+
parser.addoption(
36+
"--dask-scheduler", type=str, action="store", default="synchronous",
37+
help=(
38+
"Set the dask scheduler. Valid options include `synchronous' (the default), "
39+
"`distributed', `multiprocessing', `processes', `single-threaded', "
40+
"`sync', `synchronous', `threading', `threads'."
41+
))
42+
43+
44+
@pytest.fixture(autouse=True, scope='session')
45+
def disable_dask_threads(request):
46+
"""
47+
Currently the tests will regularly segfault while subsetting ugrid datasets.
48+
This only happens when using the latest dependencies installed from PyPI.
49+
Using older dependencies from PyPI or using latest dependencies from
50+
conda-forge continues to work fine.
51+
52+
Disabling dask multithreading stops the issue.
53+
This is a temporary work around while the issue is investigated.
54+
55+
To restore the default behaviour switch to the 'threads' scheduler:
56+
57+
$ pytest --dask-scheduler 'threads'
58+
59+
See also
60+
--------
61+
:option:`--dask-scheduler`
62+
https://github.com/csiro-coasts/emsarray/issues/139
63+
"""
64+
dask.config.set(scheduler=request.config.option.dask_scheduler)
65+
66+
2367
@pytest.fixture
2468
def matplotlib_backend(
2569
request: pytest.FixtureRequest,

0 commit comments

Comments
 (0)