Hello! I am trying to parallelise a SALOME script using Python’s multiprocessing
library but I’m running into some issues.
Consider the following snippet
import sys
import salome
import random
import multiprocessing as mp
salome.salome_init()
import salome_notebook
notebook = salome_notebook.NoteBook()
###
### GEOM component
###
import GEOM
from salome.geom import geomBuilder
import math
import SALOMEDS
geompy = geomBuilder.New()
def workerFun(args):
return geompy.MakeVertex(random.uniform(0, 10), random.uniform(0, 10), random.uniform(0, 10))
N_PROCESSES = 1
params = range(20)
if N_PROCESSES > 1:
p = mp.Pool(N_PROCESSES)
pipes = list(p.map(workerFun, params))
p.close()
p.join()
else:
pipes = list(map(workerFun, params))
[geompy.addToStudy( v, 'Vertex_{}'.format(idx)) for idx, v in enumerate(pipes)]
If I run it as it is, it will create 20 points and add them to the study. If I set, for example, N_PROCESSES = 2
, it will run but print a series of addToStudy() failed
and, in fact, it will not create any points.
Does anyone know why this is happening or how to solve this?
Thanks in advance!