In the Python API, how can I redirect the output of an asynchronous function call of a function without return value?

조회 수: 12 (최근 30일)
I am using the Python API and I want to redirect the output of an asynchronously called function without return value. Is this maybe impossible?
My Python Script looks a little bit like this:
import matlab.engine as eng
import StringIO
out = StringIO.StringIO()
MAT = eng.start_matlab()
ret = MAT.func('arg', async=True, nargout=0, stdout=out)
while not ret.done() : pass
print out.getvalue()
MAT.quit()
When running this script, there is only a line feed / carriage return printed. The return value of
ret.result()
is "None".

채택된 답변

Bo Li
Bo Li 2017년 2월 16일
What about adding "ret.result()" before printing the output buffer like following?
while not ret.done() : pass
ret.result()
print out.getvalue()
  댓글 수: 3
Esteban Henriques
Esteban Henriques 2018년 5월 11일
편집: Esteban Henriques 2018년 5월 11일
From:
def result(self, timeout=None):
in fevalfuture.py, it seems that it is not possible to get any feedback from the out stream until the call is done. Doesn't this at least in part defeat the purpose of an async call?
Sven-Eric Krüger
Sven-Eric Krüger 2018년 5월 14일
편집: Sven-Eric Krüger 2018년 5월 14일
@Esteban MATLAB itself is always single threaded, but you can asyncronuously call functions. So the Python Script will not hold on the call of the MATLAB Engine, but continue. The MATLAB Interpreter does his stuff on his own and so does the Python Interpreter.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Call MATLAB from Python에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by