|
|
|
@ -24,6 +24,7 @@ import types |
|
|
|
|
from typing import ( |
|
|
|
|
Any, |
|
|
|
|
Callable, |
|
|
|
|
Dict, |
|
|
|
|
Iterator, |
|
|
|
|
List, |
|
|
|
|
Optional, |
|
|
|
@ -1054,6 +1055,7 @@ class _UnaryUnaryMultiCallable(grpc.UnaryUnaryMultiCallable): |
|
|
|
|
_request_serializer: Optional[SerializingFunction] |
|
|
|
|
_response_deserializer: Optional[DeserializingFunction] |
|
|
|
|
_context: Any |
|
|
|
|
_registered_call_handle: Optional[int] |
|
|
|
|
|
|
|
|
|
__slots__ = [ |
|
|
|
|
"_channel", |
|
|
|
@ -1074,6 +1076,7 @@ class _UnaryUnaryMultiCallable(grpc.UnaryUnaryMultiCallable): |
|
|
|
|
target: bytes, |
|
|
|
|
request_serializer: Optional[SerializingFunction], |
|
|
|
|
response_deserializer: Optional[DeserializingFunction], |
|
|
|
|
_registered_call_handle: Optional[int], |
|
|
|
|
): |
|
|
|
|
self._channel = channel |
|
|
|
|
self._managed_call = managed_call |
|
|
|
@ -1082,6 +1085,7 @@ class _UnaryUnaryMultiCallable(grpc.UnaryUnaryMultiCallable): |
|
|
|
|
self._request_serializer = request_serializer |
|
|
|
|
self._response_deserializer = response_deserializer |
|
|
|
|
self._context = cygrpc.build_census_context() |
|
|
|
|
self._registered_call_handle = _registered_call_handle |
|
|
|
|
|
|
|
|
|
def _prepare( |
|
|
|
|
self, |
|
|
|
@ -1153,6 +1157,7 @@ class _UnaryUnaryMultiCallable(grpc.UnaryUnaryMultiCallable): |
|
|
|
|
), |
|
|
|
|
), |
|
|
|
|
self._context, |
|
|
|
|
self._registered_call_handle, |
|
|
|
|
) |
|
|
|
|
event = call.next_event() |
|
|
|
|
_handle_event(event, state, self._response_deserializer) |
|
|
|
@ -1221,6 +1226,7 @@ class _UnaryUnaryMultiCallable(grpc.UnaryUnaryMultiCallable): |
|
|
|
|
(operations,), |
|
|
|
|
event_handler, |
|
|
|
|
self._context, |
|
|
|
|
self._registered_call_handle, |
|
|
|
|
) |
|
|
|
|
return _MultiThreadedRendezvous( |
|
|
|
|
state, call, self._response_deserializer, deadline |
|
|
|
@ -1234,6 +1240,7 @@ class _SingleThreadedUnaryStreamMultiCallable(grpc.UnaryStreamMultiCallable): |
|
|
|
|
_request_serializer: Optional[SerializingFunction] |
|
|
|
|
_response_deserializer: Optional[DeserializingFunction] |
|
|
|
|
_context: Any |
|
|
|
|
_registered_call_handle: Optional[int] |
|
|
|
|
|
|
|
|
|
__slots__ = [ |
|
|
|
|
"_channel", |
|
|
|
@ -1252,6 +1259,7 @@ class _SingleThreadedUnaryStreamMultiCallable(grpc.UnaryStreamMultiCallable): |
|
|
|
|
target: bytes, |
|
|
|
|
request_serializer: SerializingFunction, |
|
|
|
|
response_deserializer: DeserializingFunction, |
|
|
|
|
_registered_call_handle: Optional[int], |
|
|
|
|
): |
|
|
|
|
self._channel = channel |
|
|
|
|
self._method = method |
|
|
|
@ -1259,6 +1267,7 @@ class _SingleThreadedUnaryStreamMultiCallable(grpc.UnaryStreamMultiCallable): |
|
|
|
|
self._request_serializer = request_serializer |
|
|
|
|
self._response_deserializer = response_deserializer |
|
|
|
|
self._context = cygrpc.build_census_context() |
|
|
|
|
self._registered_call_handle = _registered_call_handle |
|
|
|
|
|
|
|
|
|
def __call__( # pylint: disable=too-many-locals |
|
|
|
|
self, |
|
|
|
@ -1317,6 +1326,7 @@ class _SingleThreadedUnaryStreamMultiCallable(grpc.UnaryStreamMultiCallable): |
|
|
|
|
call_credentials, |
|
|
|
|
operations_and_tags, |
|
|
|
|
self._context, |
|
|
|
|
self._registered_call_handle, |
|
|
|
|
) |
|
|
|
|
return _SingleThreadedRendezvous( |
|
|
|
|
state, call, self._response_deserializer, deadline |
|
|
|
@ -1331,6 +1341,7 @@ class _UnaryStreamMultiCallable(grpc.UnaryStreamMultiCallable): |
|
|
|
|
_request_serializer: Optional[SerializingFunction] |
|
|
|
|
_response_deserializer: Optional[DeserializingFunction] |
|
|
|
|
_context: Any |
|
|
|
|
_registered_call_handle: Optional[int] |
|
|
|
|
|
|
|
|
|
__slots__ = [ |
|
|
|
|
"_channel", |
|
|
|
@ -1351,6 +1362,7 @@ class _UnaryStreamMultiCallable(grpc.UnaryStreamMultiCallable): |
|
|
|
|
target: bytes, |
|
|
|
|
request_serializer: SerializingFunction, |
|
|
|
|
response_deserializer: DeserializingFunction, |
|
|
|
|
_registered_call_handle: Optional[int], |
|
|
|
|
): |
|
|
|
|
self._channel = channel |
|
|
|
|
self._managed_call = managed_call |
|
|
|
@ -1359,6 +1371,7 @@ class _UnaryStreamMultiCallable(grpc.UnaryStreamMultiCallable): |
|
|
|
|
self._request_serializer = request_serializer |
|
|
|
|
self._response_deserializer = response_deserializer |
|
|
|
|
self._context = cygrpc.build_census_context() |
|
|
|
|
self._registered_call_handle = _registered_call_handle |
|
|
|
|
|
|
|
|
|
def __call__( # pylint: disable=too-many-locals |
|
|
|
|
self, |
|
|
|
@ -1408,6 +1421,7 @@ class _UnaryStreamMultiCallable(grpc.UnaryStreamMultiCallable): |
|
|
|
|
operations, |
|
|
|
|
_event_handler(state, self._response_deserializer), |
|
|
|
|
self._context, |
|
|
|
|
self._registered_call_handle, |
|
|
|
|
) |
|
|
|
|
return _MultiThreadedRendezvous( |
|
|
|
|
state, call, self._response_deserializer, deadline |
|
|
|
@ -1422,6 +1436,7 @@ class _StreamUnaryMultiCallable(grpc.StreamUnaryMultiCallable): |
|
|
|
|
_request_serializer: Optional[SerializingFunction] |
|
|
|
|
_response_deserializer: Optional[DeserializingFunction] |
|
|
|
|
_context: Any |
|
|
|
|
_registered_call_handle: Optional[int] |
|
|
|
|
|
|
|
|
|
__slots__ = [ |
|
|
|
|
"_channel", |
|
|
|
@ -1442,6 +1457,7 @@ class _StreamUnaryMultiCallable(grpc.StreamUnaryMultiCallable): |
|
|
|
|
target: bytes, |
|
|
|
|
request_serializer: Optional[SerializingFunction], |
|
|
|
|
response_deserializer: Optional[DeserializingFunction], |
|
|
|
|
_registered_call_handle: Optional[int], |
|
|
|
|
): |
|
|
|
|
self._channel = channel |
|
|
|
|
self._managed_call = managed_call |
|
|
|
@ -1450,6 +1466,7 @@ class _StreamUnaryMultiCallable(grpc.StreamUnaryMultiCallable): |
|
|
|
|
self._request_serializer = request_serializer |
|
|
|
|
self._response_deserializer = response_deserializer |
|
|
|
|
self._context = cygrpc.build_census_context() |
|
|
|
|
self._registered_call_handle = _registered_call_handle |
|
|
|
|
|
|
|
|
|
def _blocking( |
|
|
|
|
self, |
|
|
|
@ -1482,6 +1499,7 @@ class _StreamUnaryMultiCallable(grpc.StreamUnaryMultiCallable): |
|
|
|
|
augmented_metadata, initial_metadata_flags |
|
|
|
|
), |
|
|
|
|
self._context, |
|
|
|
|
self._registered_call_handle, |
|
|
|
|
) |
|
|
|
|
_consume_request_iterator( |
|
|
|
|
request_iterator, state, call, self._request_serializer, None |
|
|
|
@ -1572,6 +1590,7 @@ class _StreamUnaryMultiCallable(grpc.StreamUnaryMultiCallable): |
|
|
|
|
), |
|
|
|
|
event_handler, |
|
|
|
|
self._context, |
|
|
|
|
self._registered_call_handle, |
|
|
|
|
) |
|
|
|
|
_consume_request_iterator( |
|
|
|
|
request_iterator, |
|
|
|
@ -1593,6 +1612,7 @@ class _StreamStreamMultiCallable(grpc.StreamStreamMultiCallable): |
|
|
|
|
_request_serializer: Optional[SerializingFunction] |
|
|
|
|
_response_deserializer: Optional[DeserializingFunction] |
|
|
|
|
_context: Any |
|
|
|
|
_registered_call_handle: Optional[int] |
|
|
|
|
|
|
|
|
|
__slots__ = [ |
|
|
|
|
"_channel", |
|
|
|
@ -1611,8 +1631,9 @@ class _StreamStreamMultiCallable(grpc.StreamStreamMultiCallable): |
|
|
|
|
managed_call: IntegratedCallFactory, |
|
|
|
|
method: bytes, |
|
|
|
|
target: bytes, |
|
|
|
|
request_serializer: Optional[SerializingFunction] = None, |
|
|
|
|
response_deserializer: Optional[DeserializingFunction] = None, |
|
|
|
|
request_serializer: Optional[SerializingFunction], |
|
|
|
|
response_deserializer: Optional[DeserializingFunction], |
|
|
|
|
_registered_call_handle: Optional[int], |
|
|
|
|
): |
|
|
|
|
self._channel = channel |
|
|
|
|
self._managed_call = managed_call |
|
|
|
@ -1621,6 +1642,7 @@ class _StreamStreamMultiCallable(grpc.StreamStreamMultiCallable): |
|
|
|
|
self._request_serializer = request_serializer |
|
|
|
|
self._response_deserializer = response_deserializer |
|
|
|
|
self._context = cygrpc.build_census_context() |
|
|
|
|
self._registered_call_handle = _registered_call_handle |
|
|
|
|
|
|
|
|
|
def __call__( |
|
|
|
|
self, |
|
|
|
@ -1662,6 +1684,7 @@ class _StreamStreamMultiCallable(grpc.StreamStreamMultiCallable): |
|
|
|
|
operations, |
|
|
|
|
event_handler, |
|
|
|
|
self._context, |
|
|
|
|
self._registered_call_handle, |
|
|
|
|
) |
|
|
|
|
_consume_request_iterator( |
|
|
|
|
request_iterator, |
|
|
|
@ -1751,7 +1774,8 @@ def _channel_managed_call_management(state: _ChannelCallState): |
|
|
|
|
credentials: Optional[cygrpc.CallCredentials], |
|
|
|
|
operations: Sequence[Sequence[cygrpc.Operation]], |
|
|
|
|
event_handler: UserTag, |
|
|
|
|
context, |
|
|
|
|
context: Any, |
|
|
|
|
_registered_call_handle: Optional[int], |
|
|
|
|
) -> cygrpc.IntegratedCall: |
|
|
|
|
"""Creates a cygrpc.IntegratedCall. |
|
|
|
|
|
|
|
|
@ -1768,6 +1792,8 @@ def _channel_managed_call_management(state: _ChannelCallState): |
|
|
|
|
event_handler: A behavior to call to handle the events resultant from |
|
|
|
|
the operations on the call. |
|
|
|
|
context: Context object for distributed tracing. |
|
|
|
|
_registered_call_handle: An int representing the call handle of the |
|
|
|
|
method, or None if the method is not registered. |
|
|
|
|
Returns: |
|
|
|
|
A cygrpc.IntegratedCall with which to conduct an RPC. |
|
|
|
|
""" |
|
|
|
@ -1788,6 +1814,7 @@ def _channel_managed_call_management(state: _ChannelCallState): |
|
|
|
|
credentials, |
|
|
|
|
operations_and_tags, |
|
|
|
|
context, |
|
|
|
|
_registered_call_handle, |
|
|
|
|
) |
|
|
|
|
if state.managed_calls == 0: |
|
|
|
|
state.managed_calls = 1 |
|
|
|
@ -2021,6 +2048,7 @@ class Channel(grpc.Channel): |
|
|
|
|
_call_state: _ChannelCallState |
|
|
|
|
_connectivity_state: _ChannelConnectivityState |
|
|
|
|
_target: str |
|
|
|
|
_registered_call_handles: Dict[str, int] |
|
|
|
|
|
|
|
|
|
def __init__( |
|
|
|
|
self, |
|
|
|
@ -2055,6 +2083,22 @@ class Channel(grpc.Channel): |
|
|
|
|
if cygrpc.g_gevent_activated: |
|
|
|
|
cygrpc.gevent_increment_channel_count() |
|
|
|
|
|
|
|
|
|
def _get_registered_call_handle(self, method: str) -> int: |
|
|
|
|
""" |
|
|
|
|
Get the registered call handle for a method. |
|
|
|
|
|
|
|
|
|
This is a semi-private method. It is intended for use only by gRPC generated code. |
|
|
|
|
|
|
|
|
|
This method is not thread-safe. |
|
|
|
|
|
|
|
|
|
Args: |
|
|
|
|
method: Required, the method name for the RPC. |
|
|
|
|
|
|
|
|
|
Returns: |
|
|
|
|
The registered call handle pointer in the form of a Python Long. |
|
|
|
|
""" |
|
|
|
|
return self._channel.get_registered_call_handle(_common.encode(method)) |
|
|
|
|
|
|
|
|
|
def _process_python_options( |
|
|
|
|
self, python_options: Sequence[ChannelArgumentType] |
|
|
|
|
) -> None: |
|
|
|
@ -2078,12 +2122,17 @@ class Channel(grpc.Channel): |
|
|
|
|
) -> None: |
|
|
|
|
_unsubscribe(self._connectivity_state, callback) |
|
|
|
|
|
|
|
|
|
# pylint: disable=arguments-differ |
|
|
|
|
def unary_unary( |
|
|
|
|
self, |
|
|
|
|
method: str, |
|
|
|
|
request_serializer: Optional[SerializingFunction] = None, |
|
|
|
|
response_deserializer: Optional[DeserializingFunction] = None, |
|
|
|
|
_registered_method: Optional[bool] = False, |
|
|
|
|
) -> grpc.UnaryUnaryMultiCallable: |
|
|
|
|
_registered_call_handle = None |
|
|
|
|
if _registered_method: |
|
|
|
|
_registered_call_handle = self._get_registered_call_handle(method) |
|
|
|
|
return _UnaryUnaryMultiCallable( |
|
|
|
|
self._channel, |
|
|
|
|
_channel_managed_call_management(self._call_state), |
|
|
|
@ -2091,14 +2140,20 @@ class Channel(grpc.Channel): |
|
|
|
|
_common.encode(self._target), |
|
|
|
|
request_serializer, |
|
|
|
|
response_deserializer, |
|
|
|
|
_registered_call_handle, |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
# pylint: disable=arguments-differ |
|
|
|
|
def unary_stream( |
|
|
|
|
self, |
|
|
|
|
method: str, |
|
|
|
|
request_serializer: Optional[SerializingFunction] = None, |
|
|
|
|
response_deserializer: Optional[DeserializingFunction] = None, |
|
|
|
|
_registered_method: Optional[bool] = False, |
|
|
|
|
) -> grpc.UnaryStreamMultiCallable: |
|
|
|
|
_registered_call_handle = None |
|
|
|
|
if _registered_method: |
|
|
|
|
_registered_call_handle = self._get_registered_call_handle(method) |
|
|
|
|
# NOTE(rbellevi): Benchmarks have shown that running a unary-stream RPC |
|
|
|
|
# on a single Python thread results in an appreciable speed-up. However, |
|
|
|
|
# due to slight differences in capability, the multi-threaded variant |
|
|
|
@ -2110,6 +2165,7 @@ class Channel(grpc.Channel): |
|
|
|
|
_common.encode(self._target), |
|
|
|
|
request_serializer, |
|
|
|
|
response_deserializer, |
|
|
|
|
_registered_call_handle, |
|
|
|
|
) |
|
|
|
|
else: |
|
|
|
|
return _UnaryStreamMultiCallable( |
|
|
|
@ -2119,14 +2175,20 @@ class Channel(grpc.Channel): |
|
|
|
|
_common.encode(self._target), |
|
|
|
|
request_serializer, |
|
|
|
|
response_deserializer, |
|
|
|
|
_registered_call_handle, |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
# pylint: disable=arguments-differ |
|
|
|
|
def stream_unary( |
|
|
|
|
self, |
|
|
|
|
method: str, |
|
|
|
|
request_serializer: Optional[SerializingFunction] = None, |
|
|
|
|
response_deserializer: Optional[DeserializingFunction] = None, |
|
|
|
|
_registered_method: Optional[bool] = False, |
|
|
|
|
) -> grpc.StreamUnaryMultiCallable: |
|
|
|
|
_registered_call_handle = None |
|
|
|
|
if _registered_method: |
|
|
|
|
_registered_call_handle = self._get_registered_call_handle(method) |
|
|
|
|
return _StreamUnaryMultiCallable( |
|
|
|
|
self._channel, |
|
|
|
|
_channel_managed_call_management(self._call_state), |
|
|
|
@ -2134,14 +2196,20 @@ class Channel(grpc.Channel): |
|
|
|
|
_common.encode(self._target), |
|
|
|
|
request_serializer, |
|
|
|
|
response_deserializer, |
|
|
|
|
_registered_call_handle, |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
# pylint: disable=arguments-differ |
|
|
|
|
def stream_stream( |
|
|
|
|
self, |
|
|
|
|
method: str, |
|
|
|
|
request_serializer: Optional[SerializingFunction] = None, |
|
|
|
|
response_deserializer: Optional[DeserializingFunction] = None, |
|
|
|
|
_registered_method: Optional[bool] = False, |
|
|
|
|
) -> grpc.StreamStreamMultiCallable: |
|
|
|
|
_registered_call_handle = None |
|
|
|
|
if _registered_method: |
|
|
|
|
_registered_call_handle = self._get_registered_call_handle(method) |
|
|
|
|
return _StreamStreamMultiCallable( |
|
|
|
|
self._channel, |
|
|
|
|
_channel_managed_call_management(self._call_state), |
|
|
|
@ -2149,6 +2217,7 @@ class Channel(grpc.Channel): |
|
|
|
|
_common.encode(self._target), |
|
|
|
|
request_serializer, |
|
|
|
|
response_deserializer, |
|
|
|
|
_registered_call_handle, |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
def _unsubscribe_all(self) -> None: |
|
|
|
|