how can i use python multiprocessing module to run matalb engine for each process?

I'm trying to run matlab function within a python program through matlab engine in MacOS. when i run matlab engine without multiprocessing module, it runs quite well; when i run matlab engine with multiprocessing module like below, the matlab process status from running to sleeping, and never change. code:
class Demo():
def antDemo(self, lock, alive, ready):
print "now"
current = os.getcwd()
aissig = os.path.join(current, './AISSig')
os.chdir('../singleantv2.0.1/')
print "current pwd is %s" % os.getcwd()
print ready, alive
eng = matlab.engine.start_matlab()
print alive
while(alive):
lock.acquire()
file_name = alive[0]
del alive[0]
ready.append(file_name)
lock.release()
print file_name
if file_name == '.' or file_name == '..' or file_name == '.DS_Store':
continue
sigpath = os.path.join(aissig, file_name)
eng.Main(sigpath)
eng.quit()
os.chdir('../devops/')
def test1(self, lock, alive, ready):
print "start"
eng1 = matlab.engine.start_matlab()
eng1.quit()
print "end"
def test2(self, lock, alive, ready):
print "start"
eng2 = matlab1.engine.start_matlab()
eng2.quit()
print "end"
demo = Demo()
def multiproc():
file_list = os.listdir('./AISSig')
alive = file_list
ready = []
lock = multiprocessing.Lock()
#proc1 = multiprocessing.Process(target = self.antDemo, args = (lock, alive, ready))
#proc2 = multiprocessing.Process(target = self.antDemo, args = (lock, alive, ready))
#proc3 = Process(target = self.test1, args = (lock, alive, ready))
proc4 = multiprocessing.Process(target = demo.test2, args = (lock, alive, ready))
proc4.daemon = True
print proc4.is_alive()
#proc1.start()
#proc2.start()
#proc3.start()
proc4.start()
proc4.join()
print "hello"
Is there something wrong?

4 commentaires

Did you end up finding a solution? I have a similar problem when using mulitprocessing with MATLAB and MATLAB is stuck when I access eng.workspace.
I've faced the similar problems. there is no return and stuck during the multiprocessing module. I found a possible solution from the Matlabe website which shows the Limitations to Python Support
"Modules that start MATLAB in a separate process, for example, the multiprocessing module."
I Think this might be the reason why I cannot use this to do the multiprocessing with matlab engine.
What is your matlab version.
The current version does support starting of multiple instances of the engine.
I belive OP was talking about multiprocessing rather than starting multiple instances
Does anyone have a workaround?

Connectez-vous pour commenter.

Réponses (0)

Catégories

Commenté :

le 23 Juin 2021

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by