Is there a way to asynchronously startup and run matlab commands from python using the matlab API for python without waiting for startup?

6 views (last 30 days)
I am trying to call an optimization scheme from matlab using a python script. The goal is to retain control over my python script (to execute other commands) while matlab starts up and runs the optimization scheme in the background. The problem is that using the async option to start up matlab and to run matlab scripts/functions requires matlab to start in the background before any other python commands below the next matlab asynchronous command will execute. Is there a way to "stack" the asynchronous matlab startup with the other asynchronous matlab tasks so my python script can run through the rest of its code without waiting for the matlab start up? Python code attached for calling the sqrt matlab function asynchronously with sample output at the bottom. Using python 3.4.4 and matlab 2017a on Windows 10.
import matlab.engine as meng
# Start matlab asynchronously without loading JVM software to speed things up
eng = meng.start_matlab("-nojvm", async = True)
# Now call matlab to compute something asynchronously and print to see execution order
print('I am printed to screen when this python code is run')
ret1 = eng.result().sqrt(4.0, async = True)
print('I am printed to screen after matlab starts up')
Output from python
# I am processed when this python code is run
# 2.0
# I am processed in python after matlab starts up

Answers (0)

Community Treasure Hunt

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

Start Hunting!