From 65c3ca20c70ab9b338b1f3e6ac755ada9316130f Mon Sep 17 00:00:00 2001 From: Anil Tuncel Date: Wed, 8 May 2024 11:36:10 +0200 Subject: [PATCH] further restrict IsolatedProcess by multiprocessing fork --- bluecellulab/simulation/parallel.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/bluecellulab/simulation/parallel.py b/bluecellulab/simulation/parallel.py index 676afd56..1d8789ff 100644 --- a/bluecellulab/simulation/parallel.py +++ b/bluecellulab/simulation/parallel.py @@ -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 @@ -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): @@ -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