콘텐츠로 이동

Future

class Future

Represents a future for retrieving the result of asynchronous inference.

This class provides a mechanism similar to C++11 std::future, allowing access to the result of an asynchronous inference operation initiated via Model.infer_async(). For details on C++11 std::future, refer to https://en.cppreference.com/w/cpp/thread/future.html .

The Future object enables the caller to:

  • Wait for the inference to complete (wait_for)
  • Block until completion and retrieve the output (get)

Methods

Name Description
__init__
from_cpp
wait_for Waits for asynchronous inference to complete or until the timeout elapses.
get Blocks until asynchronous inference completes and retrieves the output.

__init__

def __init__(
    self,
    _future: Optional[
        Union[_cQbRuntime.FutureFloat, _cQbRuntime.FutureInt8]
    ] = None,
    _inputs: Optional[List[np.ndarray]] = None,
):
    # If parameters are None, it indicates invalid access.
    # Set FutureFloat by default just to raise error with `get` method.

from_cpp

def from_cpp(
    cls,
    _future: Union[_cQbRuntime.FutureFloat, _cQbRuntime.FutureInt8],
    _inputs: List[np.ndarray],
)

wait_for

def wait_for(self, timeout_ms: int) -> bool

Waits for asynchronous inference to complete or until the timeout elapses.

Note

This method is safe to call multiple times. Calling it with a timeout of zero (i.e., wait_for(0)) performs a non-blocking check to see whether asynchronous inference has already completed.

Parameters

  • timeout_ms [in] — Maximum duration to wait, in milliseconds.

Returns

True if inference completed before the timeout, false otherwise.

get

def get(self) -> List[np.ndarray]

Blocks until asynchronous inference completes and retrieves the output.

Note

This method should be called only once per Future. If called again, the return value will be invalid, and it will raise qbruntime.QbRuntimeError "Future_NotValid".

Returns

A list of numpy ndarray containing the inference output.