On January 1, 2020 this library will no longer support Python 2 on the latest released version. Previously released library versions will continue to be available. For more information please visit Python 2 support on Google Cloud.

Futures

Futures for dealing with asynchronous operations.

class google.api_core.future.Future[source]

Bases: object

Future interface.

This interface is based on concurrent.futures.Future.

Abstract and helper bases for Future implementations.

class google.api_core.future.polling.PollingFuture(retry=<google.api_core.retry.Retry object>)[source]

Bases: google.api_core.future.base.Future

A Future that needs to poll some service to check its status.

The done() method should be implemented by subclasses. The polling behavior will repeatedly call done until it returns True.

Parameters

retry (google.api_core.retry.Retry) – The retry configuration used when polling. This can be used to control how often done() is polled. Regardless of the retry’s deadline, it will be overridden by the timeout argument to result().

add_done_callback(fn)[source]

Add a callback to be executed when the operation is complete.

If the operation is not already complete, this will start a helper thread to poll for the status of the operation in the background.

Parameters

fn (Callable[Future]) – The callback to execute when the operation is complete.

abstract done(retry=<google.api_core.retry.Retry object>)[source]

Checks to see if the operation is complete.

Parameters

retry (google.api_core.retry.Retry) – (Optional) How to retry the RPC.

Returns

True if the operation is complete, False otherwise.

Return type

bool

exception(timeout=None)[source]

Get the exception from the operation, blocking if necessary.

Parameters

timeout (int) – How long to wait for the operation to complete. If None, wait indefinitely.

Returns

The operation’s

error.

Return type

Optional[google.api_core.GoogleAPICallError]

result(timeout=None)[source]

Get the result of the operation, blocking if necessary.

Parameters

timeout (int) – How long (in seconds) to wait for the operation to complete. If None, wait indefinitely.

Returns

The Operation’s result.

Return type

google.protobuf.Message

Raises

google.api_core.GoogleAPICallError – If the operation errors or if the timeout is reached before the operation completes.

running()[source]

True if the operation is currently running.

set_exception(exception)[source]

Set the Future’s exception.

set_result(result)[source]

Set the Future’s result.

AsyncIO implementation of the abstract base Future class.

class google.api_core.future.async_future.AsyncFuture(retry=<google.api_core.retry_async.AsyncRetry object>)[source]

Bases: google.api_core.future.base.Future

A Future that polls peer service to self-update.

The done() method should be implemented by subclasses. The polling behavior will repeatedly call done until it returns True.

Parameters

retry (google.api_core.retry.Retry) – The retry configuration used when polling. This can be used to control how often done() is polled. Regardless of the retry’s deadline, it will be overridden by the timeout argument to result().

add_done_callback(fn)[source]

Add a callback to be executed when the operation is complete.

If the operation is completed, the callback will be scheduled onto the event loop. Otherwise, the callback will be stored and invoked when the future is done.

Parameters

fn (Callable[Future]) – The callback to execute when the operation is complete.

async done(retry=<google.api_core.retry_async.AsyncRetry object>)[source]

Checks to see if the operation is complete.

Parameters

retry (google.api_core.retry.Retry) – (Optional) How to retry the RPC.

Returns

True if the operation is complete, False otherwise.

Return type

bool

async exception(timeout=None)[source]

Get the exception from the operation.

Parameters

timeout (int) – How long to wait for the operation to complete. If None, wait indefinitely.

Returns

The operation’s

error.

Return type

Optional[google.api_core.GoogleAPICallError]

async result(timeout=None)[source]

Get the result of the operation.

Parameters

timeout (int) – How long (in seconds) to wait for the operation to complete. If None, wait indefinitely.

Returns

The Operation’s result.

Return type

google.protobuf.Message

Raises

google.api_core.GoogleAPICallError – If the operation errors or if the timeout is reached before the operation completes.

async running()[source]

True if the operation is currently running.

set_exception(exception)[source]

Set the Future’s exception.

set_result(result)[source]

Set the Future’s result.