Don't let threads die over timed out RPCs

pull/22104/head
Richard Belleville 5 years ago
parent 9ef83ee539
commit 7a129dac1c
  1. 37
      src/python/grpcio_tests/tests/interop/xds_interop_client.py

@ -126,23 +126,28 @@ def _run_single_channel(args: argparse.Namespace):
sys.stdout.flush() sys.stdout.flush()
start = time.time() start = time.time()
end = start + duration_per_query end = start + duration_per_query
call, _ = stub.UnaryCall.with_call(messages_pb2.SimpleRequest(), try:
timeout=float( response, call = stub.UnaryCall.with_call(messages_pb2.SimpleRequest(),
args.rpc_timeout_sec)) timeout=float(
print(f"Got result {request_id}") args.rpc_timeout_sec))
sys.stdout.flush() except grpc.RpcError as e:
with _global_lock: if e.code() == grpc.StatusCode.DEADLINE_EXCEEDED:
for watcher in _watchers: print(f"RPC timed out after {args.rpc_timeout_sec}")
# TODO: Implement a peer details getter.
peer = f"192.168.1.{request_id % 255}"
watcher.on_rpc_complete(request_id, peer)
if args.print_response:
if call.code() == grpc.StatusCode.OK:
print("Successful response.")
sys.stdout.flush()
else: else:
print(f"RPC failed: {call}") raise
sys.stdout.flush() else:
print(f"Got result {request_id}")
sys.stdout.flush()
with _global_lock:
for watcher in _watchers:
watcher.on_rpc_complete(request_id, response.hostname)
if args.print_response:
if call.code() == grpc.StatusCode.OK:
print("Successful response.")
sys.stdout.flush()
else:
print(f"RPC failed: {call}")
sys.stdout.flush()
now = time.time() now = time.time()
while now < end: while now < end:
time.sleep(end - now) time.sleep(end - now)

Loading…
Cancel
Save