pull/21458/head
Richard Belleville 5 years ago
parent 2c1efcd0ae
commit 24a66903a9
  1. 14
      examples/python/cancellation/search.py
  2. 4
      examples/python/cancellation/server.py
  3. 3
      examples/python/compression/server.py
  4. 4
      examples/python/debug/debug_server.py

@ -134,16 +134,14 @@ def search(target,
distance = _get_substring_hamming_distance(candidate_hash, target) distance = _get_substring_hamming_distance(candidate_hash, target)
if interesting_hamming_distance is not None and distance <= interesting_hamming_distance: if interesting_hamming_distance is not None and distance <= interesting_hamming_distance:
# Surface interesting candidates, but don't stop. # Surface interesting candidates, but don't stop.
yield protos.HashNameResponse( yield protos.HashNameResponse(secret=base64.b64encode(secret),
secret=base64.b64encode(secret), hashed_name=candidate_hash,
hashed_name=candidate_hash, hamming_distance=distance)
hamming_distance=distance)
elif distance <= ideal_distance: elif distance <= ideal_distance:
# Yield ideal candidate and end the stream. # Yield ideal candidate and end the stream.
yield protos.HashNameResponse( yield protos.HashNameResponse(secret=base64.b64encode(secret),
secret=base64.b64encode(secret), hashed_name=candidate_hash,
hashed_name=candidate_hash, hamming_distance=distance)
hamming_distance=distance)
raise StopIteration() # pylint: disable=stop-iteration-return raise StopIteration() # pylint: disable=stop-iteration-return
hashes_computed += 1 hashes_computed += 1
if hashes_computed == maximum_hashes: if hashes_computed == maximum_hashes:

@ -90,8 +90,8 @@ def _running_server(port, maximum_hashes):
# threads. # threads.
server = grpc.server(futures.ThreadPoolExecutor(max_workers=1), server = grpc.server(futures.ThreadPoolExecutor(max_workers=1),
maximum_concurrent_rpcs=1) maximum_concurrent_rpcs=1)
services.add_HashFinderServicer_to_server( services.add_HashFinderServicer_to_server(HashFinder(maximum_hashes),
HashFinder(maximum_hashes), server) server)
address = '{}:{}'.format(_SERVER_HOST, port) address = '{}:{}'.format(_SERVER_HOST, port)
actual_port = server.add_insecure_port(address) actual_port = server.add_insecure_port(address)
server.start() server.start()

@ -66,8 +66,7 @@ def run_server(server_compression, no_compress_every_n, port):
server = grpc.server(futures.ThreadPoolExecutor(), server = grpc.server(futures.ThreadPoolExecutor(),
compression=server_compression, compression=server_compression,
options=(('grpc.so_reuseport', 1),)) options=(('grpc.so_reuseport', 1),))
services.add_GreeterServicer_to_server( services.add_GreeterServicer_to_server(Greeter(no_compress_every_n), server)
Greeter(no_compress_every_n), server)
address = '{}:{}'.format(_SERVER_HOST, port) address = '{}:{}'.format(_SERVER_HOST, port)
server.add_insecure_port(address) server.add_insecure_port(address)
server.start() server.start()

@ -51,8 +51,8 @@ class FaultInjectGreeter(services.GreeterServicer):
def create_server(addr, failure_rate): def create_server(addr, failure_rate):
server = grpc.server(futures.ThreadPoolExecutor()) server = grpc.server(futures.ThreadPoolExecutor())
services.add_GreeterServicer_to_server( services.add_GreeterServicer_to_server(FaultInjectGreeter(failure_rate),
FaultInjectGreeter(failure_rate), server) server)
# Add Channelz Servicer to the gRPC server # Add Channelz Servicer to the gRPC server
channelz.add_channelz_servicer(server) channelz.add_channelz_servicer(server)

Loading…
Cancel
Save