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

2 次查看(过去 30 天)
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 个评论
Ze Wei Ng
Ze Wei Ng 2021-6-23
I belive OP was talking about multiprocessing rather than starting multiple instances
Does anyone have a workaround?

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Introduction to Installation and Licensing 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by