Return print statement output from Python file in real time when using pyrunfile
Show older comments
I have a Python file I am calling using pyrunfile in Matlab R2022b on Windows as follows:
pyrunfile("filetocall.py 'inputvar1' 'inputvar2'")
Sometimes this filetocall.py can take a while to run, and it would be nice to see the print statements in my Python code that provide updates on its progress as it's running. What it currently does is show all the print statements in one block of text after the file finishes running. From what I understand this has to do with the output generated by Python print statements being buffered and it doesn't flush the output until the Python function returns.
I've tried flushing the output buffer manually in my Python code by:
- Using sys.stdout.flush() after a print statement in my Python code
- Setting the print function's flush argument to True, ie. print('Some statement', flush=True)
but unfortunately neither worked. Is there currently no way to flush output from a Python file on the Matlab side in 'real time'? If not, it's not the end of the world, would just be handy.
Accepted Answer
More Answers (0)
Categories
Find more on Call Python from MATLAB in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
