Main Content

Invoke a Compiled MATLAB Function Asynchronously

Asynchronously invoke a compiled MATLAB® function that uses the Python® object returned from the initialize() function by passing background = True.

future = my_client.function_name(in_args, nargout=nargs,
  • my_client — Name of object returned from initialize().

  • function_name — Name of the function to invok.e

  • in_args — Comma-separated list of input arguments.

  • nargs — Number of results expected from the server.

  • out_stream — Python StringIO object receiving the console output

  • err_stream — Python StringIO object receiving the error output

When the background keyword is set to True, the MATLAB function is placed into a processing queue and a Python Future object is returned. You use the Future object to retrieve the results when the MATLAB function is finished processing.

To invoke the MATLAB function c1,c2= copy(o1,o2) from the package copier asynchronously, use the following code:

>>> import mutations
>>> import matlab
>>> myMutator = mutations.initialize()
>>> m1 = matlab.double([1,2,3])
>>> m2 = matlab.double([10,20,30])
>>> m3 = matlab.double([100,200,300])
>>> resultFuture = myMutator.mutate(m1,m2,m3, background=Truea)
>>> while !resultFuture.done():
...    time.sleep(1)
>>> result = resultFuture.result()


You can cancel asynchronous requests using the cancel() method of the Future object.

Related Topics