MATLAB Answers

Servicing Python Matlab API queries

2 views (last 30 days)
Jesse Hopkins
Jesse Hopkins on 30 Jan 2019
Hello All,
I am dabbling into the python matlab api. I'd like to use the API to enable a python program that is spawned indirectly as a result of a system call from matlab, and allow that python program to interact with the parent matlab session using the API. Something like this:
function call_external_program
matlab.engine.shareEngine; % share this engine so that we can connect to it from python script.
%launch the program in the background
if ispc
[status , result] = system('START wrapper_program.exe') %<-- note that wrapper_program.exe spawns a python program that connects back to this session...
[status , result] = system('wrapper_program &') %<-- note that wrapper_program.exe spawns a python program that connects back to this session...
% wait until we detect termination of the wrapper_program. during this time, we expect to be servicing calls to python_api_entrypoint coming from
% a python program that was spawned by wrapper_program...
while 1
%Hmm.. how can I pause here in such a way that Matlab can service the Python API?
% It only works if I put a breakpoint here!
if detected_wrapper_program_completion || timeout %don't ask how we really do this...
function dataOut = python_api_entrypoint(dataIn)
%example algorithm that we use matlab for...
dataOut = sum(dataIn);
Unfortunately, the above scheme only works if I put a breakpoint at the 'pause(0.1)' line, presumably because matlab control returns to the command line. Otherwise, matlab will not service a call from the python program unless we quickly breakout of the parent function and return matlab control to the command line. This smells like something drawnow() could help with, but no such luck. Any ideas?


Sign in to comment.

Answers (0)





Community Treasure Hunt

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

Start Hunting!