Skip to content

Commit

Permalink
Merge pull request #2153 from zm711/mac-os
Browse files Browse the repository at this point in the history
Add warning that `fork` for the `mp_context` is not recommended for macOS
  • Loading branch information
samuelgarcia authored Nov 2, 2023
2 parents 9b22340 + 8bc3b61 commit 73876bf
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
6 changes: 3 additions & 3 deletions doc/modules/core.rst
Original file line number Diff line number Diff line change
Expand Up @@ -518,9 +518,9 @@ These are a set of keyword arguments which are common to all functions that supp
A float like 0.5 means half of the availables core.
* progress_bar: bool
If True, a progress bar is printed
* mp_context: str or None
Context for multiprocessing. It can be None (default), "fork" or "spawn".
Note that "fork" is only available on UNIX systems (not Windows)
* mp_context: "fork" | "spawn" | None, default: None
"fork" or "spawn". If None, the context is taken by the recording.get_preferred_mp_context().
"fork" is only safely available on LINUX systems.

The default **job_kwargs** are :code:`n_jobs=1, chunk_duration="1s", progress_bar=True`.

Expand Down
13 changes: 8 additions & 5 deletions src/spikeinterface/core/job_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import numpy as np
import platform
import os
import warnings

import joblib
import sys
Expand All @@ -30,9 +31,9 @@
Number of jobs to use. With -1 the number of jobs is the same as number of cores
* progress_bar: bool
If True, a progress bar is printed
* mp_context: str or None
Context for multiprocessing. It can be None (default), "fork" or "spawn".
Note that "fork" is only available on UNIX systems
* mp_context: "fork" | "spawn" | None, default: None
Context for multiprocessing. It can be None, "fork" or "spawn".
Note that "fork" is only safely available on LINUX systems
"""


Expand Down Expand Up @@ -287,9 +288,9 @@ class ChunkRecordingExecutor:
Size of each chunk in number of samples. If "total_memory" or "chunk_memory" are used, it is ignored.
chunk_duration : str or float or None
Chunk duration in s if float or with units if str (e.g. "1s", "500ms")
mp_context : str or None, default: None
mp_context : "fork" | "spawn" | None, default: None
"fork" or "spawn". If None, the context is taken by the recording.get_preferred_mp_context().
"fork" is only available on UNIX systems.
"fork" is only safely available on LINUX systems.
max_threads_per_process: int or None, default: None
Limit the number of thread per process using threadpoolctl modules.
This used only when n_jobs>1
Expand Down Expand Up @@ -332,6 +333,8 @@ def __init__(
mp_context = recording.get_preferred_mp_context()
if mp_context is not None and platform.system() == "Windows":
assert mp_context != "fork", "'fork' mp_context not supported on Windows!"
elif mp_context == "fork" and platform.system() == "Darwin":
warnings.warn('As of Python 3.8 "fork" is no longer considered safe on macOS')

self.mp_context = mp_context

Expand Down

0 comments on commit 73876bf

Please sign in to comment.