This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

Call MATLAB Functions Asynchronously from Python

This example shows how to call the MATLAB® sqrt function asynchronously from Python® and retrieve the square root later.

The engine calls MATLAB functions synchronously by default. Control returns to Python only when the MATLAB function finishes. But the engine also can call functions asynchronously. Control immediately returns to Python while MATLAB is still executing the function. The engine stores the result in a Python variable that can be inspected after the function finishes.

Use the async argument to call a MATLAB function asynchronously.

import matlab.engine
eng = matlab.engine.start_matlab()
future = eng.sqrt(4.0,async=True)
ret = future.result()
print(ret)
2.0

Use the done method to check if an asynchronous call finished.

tf = future.done()
print(tf)
True

To stop execution of the function before it finishes, call future.cancel().

See Also

|

Related Topics