Skip to content

Commit

Permalink
BUG fix reported number of jobs in effective_n_jobs (#985)
Browse files Browse the repository at this point in the history
  • Loading branch information
glemaitre authored and ogrisel committed Jan 6, 2020
1 parent 12c2b2b commit f6b7990
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 1 deletion.
7 changes: 7 additions & 0 deletions CHANGES.rst
@@ -1,6 +1,13 @@
Latest changes
==============

Release 0.14.2
--------------

- Fix the number of jobs reported by ``effective_n_jobs`` when ``n_jobs=None``
called in a parallel backend context.
https://github.com/joblib/joblib/pull/985

Release 0.14.1
--------------

Expand Down
1 change: 1 addition & 0 deletions continuous_integration/travis/install.sh
Expand Up @@ -91,6 +91,7 @@ if [ -n "$NUMPY_VERSION" ]; then
fi

if [[ "$COVERAGE" == "true" ]]; then
# TODO: unpin when https://github.com/nedbat/coveragepy/issues/883 is fixed
# Weird issues with recent version of coverage: unpin when not causing
# pytest to raise INTERNALERROR exceptions.
PIP_INSTALL_PACKAGES="$PIP_INSTALL_PACKAGES coverage==4.5.4 pytest-cov codecov"
Expand Down
4 changes: 3 additions & 1 deletion joblib/parallel.py
Expand Up @@ -385,7 +385,9 @@ def effective_n_jobs(n_jobs=-1):
.. versionadded:: 0.10
"""
backend, _ = get_active_backend()
backend, backend_n_jobs = get_active_backend()
if n_jobs is None:
n_jobs = backend_n_jobs
return backend.effective_n_jobs(n_jobs=n_jobs)


Expand Down
17 changes: 17 additions & 0 deletions joblib/test/test_parallel.py
Expand Up @@ -152,6 +152,23 @@ def test_effective_n_jobs():
assert effective_n_jobs() > 0


@pytest.mark.parametrize(
"backend_n_jobs, expected_n_jobs",
[(3, 3), (-1, effective_n_jobs(n_jobs=-1)), (None, 1)],
ids=["positive-int", "negative-int", "None"]
)
@with_multiprocessing
def test_effective_n_jobs_None(backend_n_jobs, expected_n_jobs):
# check the number of effective jobs when `n_jobs=None`
# non-regression test for https://github.com/joblib/joblib/issues/984
with parallel_backend("threading", n_jobs=backend_n_jobs):
# when using a backend, the default of number jobs will be the one set
# in the backend
assert effective_n_jobs(n_jobs=None) == expected_n_jobs
# without any backend, None will default to a single job
assert effective_n_jobs(n_jobs=None) == 1


###############################################################################
# Test parallel

Expand Down

0 comments on commit f6b7990

Please sign in to comment.