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

2 visualizaciones (últimos 30 días)
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 comentarios
Ze Wei Ng
Ze Wei Ng el 23 de Jun. de 2021
I belive OP was talking about multiprocessing rather than starting multiple instances
Does anyone have a workaround?

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Introduction to Installation and Licensing en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by