Python Forum
issue with multiprocessing in embeded python
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
issue with multiprocessing in embeded python
#1
Hello,
I am strugling to use mutliprocessing with the python that is inside of salome platform.
salome platform being a CAD software, where i can create geometry objects in python.
for simplicity, i created a dummy testing case where i create random positions for vertexes and the vertexes in sequential (using list coomprehension) and then I would like to create spheres in the each of this vertexes but using multitprocessing/multithreading.
so the script looks like this:
import sys import salome salome.salome_init() import salome_notebook notebook = salome_notebook.NoteBook() sys.path.insert(0, r'/home/franco/Desktop') import GEOM from salome.geom import geomBuilder import math import SALOMEDS import random from multiprocessing import Pool geompy = geomBuilder.New() listOfPosition=[[random.random(),random.random(),random.random()] for i in range(100)] listOfVertexes=[geompy.MakeVertex(p[0], p[1], p[2]) for p in listOfPosition] listOfSpheresSerial=[geompy.MakeSpherePntR(v, 100) for v in listOfVertexes] def create_sphere(vertex): return geompy.MakeSpherePntR(vertex, 100) with Pool(processes=4) as pool: # Adjust number of processes as needed listOfSpheresParallel = pool.map(create_sphere, listOfVertexes) geompy.addToStudy(geompy.MakeCompound(listOfSpheresSerial),"") geompy.addToStudy(geompy.MakeCompound(listOfSpheresParallel),"")
as it can be seen, I am ‘creating’ two times the spheres, in a list coomprehension (ie., listOfSpheresSerial) and in multiprocessing (ie., listOfSpheresParallel)
the thing is that this runs without errors until the geompy.MakeCompound() where it fails for the list created in parallel (ie., listOfSpheresParallel). the thing is, when I print the content of listOfSpheresParallel it is same type as the one made in list coomprehension (listOfSpheresSerial). is there any way I can ‘continue’ with the one made with multiprocessing? any extra step so i can use listOfSpheresParallel normally?
the error I am getting is the following:
Traceback (most recent call last): File "<input>", line 1, in <module> File "/home/franco/Desktop/blalba.py", line 52, in <module> geompy.addToStudy(geompy.MakeCompound(listOfSpheresParallel),"") File "/home/franco/Programs/Salome/SALOME-9.14.0/BINARIES-CO7/GEOM/lib/python3.9/site-packages/salome/salome/geom/geomBuilder.py", line 368, in OpenCallClose res = theFunction(self, *args, **kwargs) File "/home/franco/Programs/Salome/SALOME-9.14.0/BINARIES-CO7/GEOM/lib/python3.9/site-packages/salome/salome/geom/geomBuilder.py", line 5122, in MakeCompound anObj = self.ShapesOp.MakeCompound(ToList(theShapes)) File "/home/franco/Programs/Salome/SALOME-9.14.0/BINARIES-CO7/GEOM/lib/python3.9/site-packages/salome/GEOM_Gen_idl.py", line 1814, in MakeCompound return self._obj.invoke("MakeCompound", _0_GEOM.GEOM_IShapesOperations._d_MakeCompound, args) omniORB.CORBA._omni_sys_exc: CORBA.OBJECT_NOT_EXIST(omniORB.OBJECT_NOT_EXIST_NoMatch, CORBA.COMPLETED_NO)
I dont know where to look, and furthermore, the salome forum is quite inactive (reason why i am asking in a general python forum)
thanks in advance
Reply
#2
I think this may be a pickling problem. What is your OS?

When running on Windows, different processes do not share the same memory space. Objects (everything in Python is an object) are passed between processes by pickling. Converting the object to a byte stream, passed to the other process, and converted back to create a new object with the same attributes. Not all objects can be pickled.

You could try an experiment to see if vertices and spheres can be pickled. Create a Vertex, pickle it and compare the pickled object against the original. Something like this:
import pickle vertex = geompy.MakeVertex(1.0, 2.0, 3.0) pickled = pickle.loads(pickle.dumps(vertex)) print(vertex == pickled)
This assumes that a vertex supports comparison.
otaolafr likes this post
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Is this a multiprocessing bug in Python - or am I doing something wrong? haimat 1 4,557 Oct-18-2023, 06:07 AM
Last Post: absalom1
  python multiprocessing help -- to extract 10 sql table into csv mg24 3 3,329 Nov-20-2022, 11:50 PM
Last Post: mg24
  python multiprocessing to download sql table mg24 5 3,618 Oct-31-2022, 03:53 PM
Last Post: Larz60+
  PyRun_SimpleFile calling multiprocessing Python Class cause endless init loop Xeno 2 2,799 Sep-19-2022, 02:32 AM
Last Post: Xeno
  Python multiprocessing Pool apply async wait for process to complete sunny9495 6 13,608 Apr-02-2022, 06:31 AM
Last Post: sunny9495
  python multiprocessing import Pool, cpu_count: causes forever loop | help to remove Hassibayub 0 3,179 Jun-18-2020, 05:27 PM
Last Post: Hassibayub
  Pexpect not catching embeded ssh response luchoArg32 0 3,399 Feb-08-2019, 08:45 AM
Last Post: luchoArg32
  Issue in my multiprocessing Python code? PrateekG 7 6,606 Jul-19-2018, 06:47 PM
Last Post: gontajones
  Python 3.5 Instantiate and manipulate object with multiprocessing jipete 1 6,123 Dec-28-2016, 12:46 AM
Last Post: micseydel

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020
This forum uses Lukasz Tkacz MyBB addons.
Forum use Krzysztof "Supryk" Supryczynski addons.