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

조회 수: 3 (최근 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
Mohammad Sami
Mohammad Sami 2020년 1월 28일
What is your matlab version.
The current version does support starting of multiple instances of the engine.
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