Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -199,5 +199,5 @@ MNE-Python is **BSD-licensed** (BSD-3-Clause):
.. |OpenSSF| image:: https://www.bestpractices.dev/projects/7783/badge
.. _OpenSSF: https://www.bestpractices.dev/projects/7783

.. |MNE| image:: https://mne.tools/stable/_static/mne_logo.svg
.. |MNE| image:: https://mne.tools/dev/_static/mne_logo_gray.svg
.. _MNE: https://mne.tools/dev/
1 change: 1 addition & 0 deletions doc/changes/devel.rst
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ Bugs
- Fix bug with :func:`mne.channels.read_ch_adjacency` (:gh:`11608` by :newcontrib:`Ivan Zubarev`)
- Fix bugs with saving splits for :class:`~mne.Epochs` (:gh:`11876` by `Dmitrii Altukhov`_)
- Fix bug with multi-plot 3D rendering where only one plot was updated (:gh:`11896` by `Eric Larson`_)
- Fix bug where ``verbose`` level was not respected inside parallel jobs (:gh:`12154` by `Eric Larson`_)
- Fix bug where subject birthdays were not correctly read by :func:`mne.io.read_raw_snirf` (:gh:`11912` by `Eric Larson`_)
- Fix bug with :func:`mne.chpi.compute_head_pos` for CTF data where digitization points were modified in-place, producing an incorrect result during a save-load round-trip (:gh:`11934` by `Eric Larson`_)
- Fix bug where non-compliant stimulus data streams were not ignored by :func:`mne.io.read_raw_snirf` (:gh:`11915` by `Johann Benerradi`_)
Expand Down
8 changes: 7 additions & 1 deletion mne/parallel.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
_validate_type,
get_config,
logger,
use_log_level,
verbose,
warn,
)
Expand Down Expand Up @@ -120,7 +121,12 @@ def parallel_func(
logger.debug(f"Got {n_jobs} parallel jobs after requesting {n_jobs_orig}")
if max_jobs is not None:
n_jobs = min(n_jobs, max(_ensure_int(max_jobs, "max_jobs"), 1))
my_func = delayed(func)

def run_verbose(*args, verbose=logger.level, **kwargs):
with use_log_level(verbose=verbose):
return func(*args, **kwargs)

my_func = delayed(run_verbose)

if total is not None:

Expand Down
22 changes: 22 additions & 0 deletions mne/utils/tests/test_logging.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import logging
import os
import re
import warnings
Expand All @@ -8,6 +9,7 @@

from mne import Epochs, create_info, read_evokeds
from mne.io import RawArray, read_raw_fif
from mne.parallel import parallel_func
from mne.utils import (
_get_call_line,
catch_logging,
Expand Down Expand Up @@ -252,3 +254,23 @@ def meth_2(self, verbose=None):
o.meth_2(verbose=False)
log = log.getvalue()
assert log == ""


@pytest.mark.parametrize("n_jobs", (1, 2))
def test_verbose_threads(n_jobs):
"""Test that our verbose level propagates to threads."""

def my_fun():
from mne.utils import logger

return logger.level

with use_log_level("info"):
assert logger.level == logging.INFO
with use_log_level("warning"):
assert logger.level == logging.WARNING
parallel, p_fun, got_jobs = parallel_func(my_fun, n_jobs=n_jobs)
assert got_jobs in (1, n_jobs) # FORCE_SERIAL could be set
out = parallel(p_fun() for _ in range(5))
want_levels = [logging.WARNING] * 5
assert out == want_levels