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