Contenuto principale

matlab.production_server.client.Future

R2026b

Namespace: matlab.production_server

An asynchronous request from the Python client to MATLAB Production Server

Description

The Future class represents an asynchronous request and provides methods to monitor and retrieve results.

Construction

Create a Future by using the matlab.production_server.client.MWHttpAsyncClient to call a function deployed to MATLAB® Production Server™.

Methods

Public Methods

fetch_outputs

future.fetch_outputs()Waits for completion and retrieves results.

result = future.fetch_outputs()

Returns: Tuple of MATLAB function outputs

wait

future.wait(state, timeout, interval) Polls until request reaches specified state.

Input Arguments

  • state – (str, default="ready") Target state to wait for

  • timeout – (float, optional) Maximum wait time in seconds (Specifying None causes the method to wait indefinitely)

  • interval–(float, default=1) Polling interval in seconds

 state = future.wait(state="ready", timeout=60, interval=0.5)

Returns: Final AsyncRequestState

cancel

client.cancel() Attempts to cancel the running request

success = future.cancel()

Returns: True if cancellation accepted, False otherwise

is_terminal

is_terminal() Checks if request has reached a terminal state

done = future.is_terminal()

Returns: True if state is READY, ERROR, or CANCELLED

Properties

expand all

This property is read-only.

Current request state, specified as an AsyncRequestState enum member. For more information, see Request States.

This property is read-only.

Input arguments used in the request, specified as a tuple.

This property is read-only.

Results of function evaluation, specified as a tuple. The results are available after calling the fetch_outputs() method.

This property is read-only.

Expected number of outputs, specified as am int.

This property is read-only.

Specified as a MATLABException if an error occurred, or as None otherwise.

Examples

collapse all

Initialize the client using matlab.production_server.client.MWHttpAsyncClient and call a function deployed to MATLAB Production Server. Use the state property to determine the current state of function execution.

import matlab
from production_server import async_client

# Create async client
client = async_client.MWHttpAsyncClient("http://localhost:9910")

# Start async function call
future = client.myArchive.addMatrices(
    matlab.double([[1, 2], [3, 4]]),
    matlab.double([[5, 6], [7, 8]]),
    nargout=1
)

# Poll state
print(f"Current state: {future.state}")
AsyncRequestState.PROCESSING

PROCESSING indicates that the function is currently executing on MATLAB Production Server.

Poll the Future until the request reaches the READY state using the wait method. Return the result of the function execution using the fetch_outputs method.

# Wait for completion
future.wait(state="ready", timeout=30)

# Retrieve results
try:
    result = future.fetch_outputs()
    print(f"Result: {result}")
except MATLABException as e:
    print(f"MATLAB error: {e.message}")
AsyncRequestState.READY
Result: (array([[6., 8.],
               [10., 12.]]),)

The READY state indicates that the request has completed successfully.

More About

expand all