Matlab Runtime "Error on flush"

조회 수: 5 (최근 30일)
KB
KB 2018년 10월 2일
댓글: W Grootjans 2025년 8월 25일 12:37
I am trying to use Python and MATLAB Runtime to call some code that was previously compiled using the MATLAB compiler. It's giving me the following error:
MatlabRuntimeError: An error occurred when evaluating the result from a function. Details: Error on flush.
Googling the error didn't turn anything up. Does anyone know what this might mean? I have double-checked that I am using the correct version of the compiler (9.4 R2018a), and I get the same error message whether I'm using Python 2.7 or 3.6. The MATLAB code works fine when run from MATLAB proper.
Any help would be very much appreciated!

답변 (4개)

Olli Tanskanen
Olli Tanskanen 2020년 8월 4일
I encountered the issue as well.
I was able to reproduce the issue reliably when using pyinstaller with console option set to false (when false it won't show a console window, only your applicaton window), but when I ran the pyinstaller with console option set to true everything worked just fine. The bug seems to be related to stdout not 'existing' which causes issues in matlab side.
I was able to fix the problem with any of these:
  1. Redirecting stdout and stderr to StringIO stream (see example below)
  2. Having a console window visible
  3. Removing all disp functions from matlab code
Example on how to redirect stdout:
import io
import your_matlab_package
p_handle = your_matlab_package.initialize()
p_handle.your_matlab_function(..., stdout=io.StringIO(), stderr=io.StringIO())
If you want to actually show matlab disp results in python side you can of couse create a new class which inherits StringIO and override the write function where you would actually show/log the matlab output.
  댓글 수: 1
W Grootjans
W Grootjans 2025년 8월 25일 12:37
Thanks for this response. This fixed my problem for this very niche use case. Very much appreciated!!!

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


Andreas Blassnig
Andreas Blassnig 2018년 11월 7일
Could you find a solution for this Problem? (I got the same error message.)
Best regards
  댓글 수: 1
KB
KB 2018년 11월 7일
Hi Andreas,
Afraid not- I haven't been able to find any more information. Maybe now that there's two of us it will help with the question's visibility, though.

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


kok wei
kok wei 2019년 6월 10일
I'm facing this issue with MATLAB R2019a and Python 3.6.8 as well. Appreciate for any further inputs.

yusuf elezler
yusuf elezler 2020년 4월 14일
편집: yusuf elezler 2020년 4월 14일
The problem is display functions like disp('xxxx'). Delete or comment it and compile again. It'll work.

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by