Evaluate a Compiled MATLAB Function Asynchronously

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

future = my_client.function_name(in_args, nargout=nargs,
                                 stdout=out_stream,
                                 stderr=err_stream,
                                 async=True)
  • my_client — Name of object returned from initialize()

  • function_name — Name of the function to invoke

  • 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 async 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(...)
>>> m2 = matlab.double(...)
>>> m3 = matlab.double(...)
>>> resultFuture = myMutator.mutate(m1,m2,m3, async=True)
>>> while !resultFuture.done():
...    time.sleep(1)
...
>>> result = resultFuture.result()

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

Related Examples

Was this topic helpful?