GeezerVison is showing github.com — AsyncIO Integration [Part 1] by lidizheng · Pull Request #26 · googleapis/python-api-core
This repository was archived by the owner on Feb 23, 2026. It is now read-only.
AsyncIO Integration [Part 1]
#26
Uh oh!
There was an error while loading. Please reload this page.
Show file tree
Hide file tree
Changes from all commits
Commits
File filter
Filter by extension
.py
(9)
.rst
(1)
All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Hide whitespace
Diff view
Hide whitespace
There are no files selected for viewing
Original file line number
Diff line number
Diff line change
Expand Up
@@ -4,3 +4,10 @@ Retry
.. automodule:: google.api_core.retry
:members:
:show-inheritance:
Retry in AsyncIO
----------------
.. automodule:: google.api_core.retry_async
:members:
:show-inheritance:
Original file line number
Diff line number
Diff line change
Expand Up
@@ -444,6 +444,10 @@ def from_grpc_status(status_code, message, **kwargs):
return error
def _is_informative_grpc_error(rpc_exc):
return hasattr(rpc_exc, "code") and hasattr(rpc_exc, "details")
def from_grpc_error(rpc_exc):
"""Create a :class:`GoogleAPICallError` from a :class:`grpc.RpcError`.
Expand All
@@ -454,7 +458,9 @@ def from_grpc_error(rpc_exc):
GoogleAPICallError: An instance of the appropriate subclass of
:class:`GoogleAPICallError`.
"""
if isinstance(rpc_exc, grpc.Call):
# NOTE(lidiz) All gRPC error shares the parent class grpc.RpcError.
# However, check for grpc.RpcError breaks backward compatibility.
if isinstance(rpc_exc, grpc.Call) or _is_informative_grpc_error(rpc_exc):
return from_grpc_status(
rpc_exc.code(), rpc_exc.details(), errors=(rpc_exc,), response=rpc_exc
)
Expand Down
Original file line number
Diff line number
Diff line change
Expand Up
@@ -12,9 +12,15 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import sys
from google.api_core.gapic_v1 import client_info
from google.api_core.gapic_v1 import config
from google.api_core.gapic_v1 import method
from google.api_core.gapic_v1 import routing_header
__all__ = ["client_info", "config", "method", "routing_header"]
if sys.version_info >= (3, 6):
from google.api_core.gapic_v1 import config_async # noqa: F401
__all__.append("config_async")
Original file line number
Diff line number
Diff line change
Expand Up
@@ -45,7 +45,7 @@ def _exception_class_for_grpc_status_name(name):
return exceptions.exception_class_for_grpc_status(getattr(grpc.StatusCode, name))
def _retry_from_retry_config(retry_params, retry_codes):
def _retry_from_retry_config(retry_params, retry_codes, retry_impl=retry.Retry ):
"""Creates a Retry object given a gapic retry configuration.
Args:
Expand All
@@ -70,7 +70,7 @@ def _retry_from_retry_config(retry_params, retry_codes):
exception_classes = [
_exception_class_for_grpc_status_name(code) for code in retry_codes
]
return retry.Retry (
return retry_impl (
retry.if_exception_type(*exception_classes),
initial=(retry_params["initial_retry_delay_millis"] / _MILLIS_PER_SECOND),
maximum=(retry_params["max_retry_delay_millis"] / _MILLIS_PER_SECOND),
Expand Down
Expand Up
@@ -110,7 +110,7 @@ def _timeout_from_retry_config(retry_params):
MethodConfig = collections.namedtuple("MethodConfig", ["retry", "timeout"])
def parse_method_configs(interface_config):
def parse_method_configs(interface_config, retry_impl=retry.Retry ):
"""Creates default retry and timeout objects for each method in a gapic
interface config.
Expand All
@@ -120,6 +120,8 @@ def parse_method_configs(interface_config):
an interface named ``google.example.v1.ExampleService`` you would
pass in just that interface's configuration, for example
``gapic_config['interfaces']['google.example.v1.ExampleService']``.
retry_impl (Callable): The constructor that creates a retry decorator
that will be applied to the method based on method configs.
Returns:
Mapping[str, MethodConfig]: A mapping of RPC method names to their
Expand Down
Expand Up
@@ -151,7 +153,7 @@ def parse_method_configs(interface_config):
if retry_params_name is not None:
retry_params = retry_params_map[retry_params_name]
retry_ = _retry_from_retry_config(
retry_params, retry_codes_map[method_params["retry_codes_name"]]
retry_params, retry_codes_map[method_params["retry_codes_name"]], retry_impl
)
timeout_ = _timeout_from_retry_config(retry_params)
Expand Down
Original file line number
Diff line number
Diff line change
@@ -0,0 +1,42 @@
# Copyright 2020 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""AsyncIO helpers for loading gapic configuration data.
The Google API generator creates supplementary configuration for each RPC
method to tell the client library how to deal with retries and timeouts.
"""
from google.api_core import retry_async
from google.api_core.gapic_v1 import config
from google.api_core.gapic_v1.config import MethodConfig # noqa: F401
def parse_method_configs(interface_config):
"""Creates default retry and timeout objects for each method in a gapic
interface config with AsyncIO semantics.
Args:
interface_config (Mapping): The interface config section of the full
gapic library config. For example, If the full configuration has
an interface named ``google.example.v1.ExampleService`` you would
pass in just that interface's configuration, for example
``gapic_config['interfaces']['google.example.v1.ExampleService']``.
Returns:
Mapping[str, MethodConfig]: A mapping of RPC method names to their
configuration.
"""
return config.parse_method_configs(
interface_config,
retry_impl=retry_async.AsyncRetry)
Loading
Oops, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.