Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

further restrict IsolatedProcess by setting multiprocessing start method #181

Merged
merged 3 commits into from
May 8, 2024
Merged
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
6 changes: 5 additions & 1 deletion bluecellulab/simulation/parallel.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Controlled simulations in parallel."""

from __future__ import annotations
import multiprocessing
from multiprocessing.pool import Pool
from bluecellulab.simulation.neuron_globals import NeuronGlobals

Expand All @@ -11,7 +12,8 @@ class IsolatedProcess(Pool):
Use this when running isolated NEURON simulations. Running 2 NEURON
simulations on a single process is to be avoided. Required global
NEURON simulation parameters will automatically be passed to each
worker.
worker. `fork` mode of multiprocessing is used to pass any other
global NEURON parameters to each worker.
"""

def __init__(self, processes: int | None = 1):
Expand All @@ -21,12 +23,14 @@ def __init__(self, processes: int | None = 1):
processes: The number of processes to use for running the simulations.
If set to None, then the number returned by os.cpu_count() is used.
"""
ctx = multiprocessing.get_context("fork")
neuron_global_params = NeuronGlobals.get_instance().export_params()
super().__init__(
processes=processes,
initializer=self.init_worker,
initargs=(neuron_global_params,),
maxtasksperchild=1,
context=ctx,
)

@staticmethod
Expand Down