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

3 ビュー (過去 30 日間)
hou jinchegn
hou jinchegn 2016 年 5 月 14 日
コメント済み: Ze Wei Ng 2021 年 6 月 23 日
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 Center および File ExchangeIntroduction 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