_channel_state.py
Go to the documentation of this file.
1 # Copyright 2017 gRPC authors.
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14 
15 import collections
16 import threading
17 
18 from grpc_testing import _common
19 from grpc_testing._channel import _rpc_state
20 
21 
23 
24  def __init__(self):
25  self._condition = threading.Condition()
26  self._rpc_states = collections.defaultdict(list)
27 
28  def invoke_rpc(self, method_full_rpc_name, invocation_metadata, requests,
29  requests_closed, timeout):
30  rpc_state = _rpc_state.State(invocation_metadata, requests,
31  requests_closed)
32  with self._condition:
33  self._rpc_states[method_full_rpc_name].append(rpc_state)
34  self._condition.notify_all()
35  return rpc_state
36 
37  def take_rpc_state(self, method_descriptor):
38  method_full_rpc_name = '/{}/{}'.format(
39  method_descriptor.containing_service.full_name,
40  method_descriptor.name)
41  with self._condition:
42  while True:
43  method_rpc_states = self._rpc_states[method_full_rpc_name]
44  if method_rpc_states:
45  return method_rpc_states.pop(0)
46  else:
47  self._condition.wait()
http2_test_server.format
format
Definition: http2_test_server.py:118
grpc_testing._channel._channel_state.State._condition
_condition
Definition: _channel_state.py:25
grpc_testing._channel._channel_state.State
Definition: _channel_state.py:22
grpc_testing._common.ChannelHandler
Definition: testing/grpc_testing/_common.py:98
grpc_testing._channel._channel_state.State.invoke_rpc
def invoke_rpc(self, method_full_rpc_name, invocation_metadata, requests, requests_closed, timeout)
Definition: _channel_state.py:28
grpc_testing._channel._rpc_state.State
Definition: _rpc_state.py:21
grpc_testing._channel._channel_state.State.__init__
def __init__(self)
Definition: _channel_state.py:24
grpc_testing._channel._channel_state.State.take_rpc_state
def take_rpc_state(self, method_descriptor)
Definition: _channel_state.py:37
wait
static void wait(notification *n)
Definition: alts_tsi_handshaker_test.cc:114
grpc_testing._channel
Definition: src/python/grpcio_testing/grpc_testing/_channel/__init__.py:1
grpc_testing._channel._channel_state.State._rpc_states
_rpc_states
Definition: _channel_state.py:26


grpc
Author(s):
autogenerated on Fri May 16 2025 02:57:38