Skip to content

Commit

Permalink
further restrict IsolatedProcess by multiprocessing fork
Browse files Browse the repository at this point in the history
  • Loading branch information
anilbey committed May 8, 2024
1 parent fcf8ad0 commit 65c3ca2
Showing 1 changed file with 5 additions and 1 deletion.
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 the other
required 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

0 comments on commit 65c3ca2

Please sign in to comment.