Merge pull request #19852 from gnossen/server_termination

Quit waiting for a day
pull/19891/head
Richard Belleville 5 years ago committed by GitHub
commit d932d2368e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      examples/python/auth/customized_auth_client.py
  2. 13
      examples/python/auth/customized_auth_server.py
  3. 6
      examples/python/auth/test/_auth_example_test.py
  4. 16
      examples/python/cancellation/server.py
  5. 8
      examples/python/compression/server.py
  6. 8
      examples/python/debug/debug_server.py
  7. 9
      examples/python/errors/server.py
  8. 9
      examples/python/helloworld/greeter_server.py
  9. 9
      examples/python/helloworld/greeter_server_with_reflection.py
  10. 9
      examples/python/interceptors/headers/greeter_server.py
  11. 9
      examples/python/metadata/metadata_server.py
  12. 8
      examples/python/multiplex/multiplex_server.py
  13. 8
      examples/python/route_guide/route_guide_server.py
  14. 2
      examples/python/wait_for_ready/wait_for_ready_example.py
  15. 11
      src/python/grpcio_tests/tests/interop/server.py

@ -29,8 +29,6 @@ from examples.python.auth import _credentials
_LOGGER = logging.getLogger(__name__)
_LOGGER.setLevel(logging.INFO)
_ONE_DAY_IN_SECONDS = 60 * 60 * 24
_SERVER_ADDR_TEMPLATE = 'localhost:%d'
_SIGNATURE_HEADER_KEY = 'x-signature'

@ -20,7 +20,6 @@ from __future__ import print_function
import argparse
import contextlib
import logging
import time
from concurrent import futures
import grpc
@ -31,8 +30,6 @@ from examples.python.auth import _credentials
_LOGGER = logging.getLogger(__name__)
_LOGGER.setLevel(logging.INFO)
_ONE_DAY_IN_SECONDS = 60 * 60 * 24
_LISTEN_ADDRESS_TEMPLATE = 'localhost:%d'
_SIGNATURE_HEADER_KEY = 'x-signature'
@ -85,7 +82,7 @@ def run_server(port):
server.start()
try:
yield port
yield server, port
finally:
server.stop(0)
@ -96,13 +93,9 @@ def main():
'--port', nargs='?', type=int, default=50051, help='the listening port')
args = parser.parse_args()
with run_server(args.port) as port:
with run_server(args.port) as (server, port):
logging.info('Server is listening at port :%d', port)
try:
while True:
time.sleep(_ONE_DAY_IN_SECONDS)
except KeyboardInterrupt:
pass
server.wait_for_termination()
if __name__ == '__main__':

@ -30,20 +30,20 @@ _SERVER_ADDR_TEMPLATE = 'localhost:%d'
class AuthExampleTest(unittest.TestCase):
def test_successful_call(self):
with customized_auth_server.run_server(0) as port:
with customized_auth_server.run_server(0) as (_, port):
with customized_auth_client.create_client_channel(
_SERVER_ADDR_TEMPLATE % port) as channel:
customized_auth_client.send_rpc(channel)
# No unhandled exception raised, test passed!
def test_no_channel_credential(self):
with customized_auth_server.run_server(0) as port:
with customized_auth_server.run_server(0) as (_, port):
with grpc.insecure_channel(_SERVER_ADDR_TEMPLATE % port) as channel:
resp = customized_auth_client.send_rpc(channel)
self.assertEqual(resp.code(), grpc.StatusCode.UNAVAILABLE)
def test_no_call_credential(self):
with customized_auth_server.run_server(0) as port:
with customized_auth_server.run_server(0) as (_, port):
channel_credential = grpc.ssl_channel_credentials(
_credentials.ROOT_CERTIFICATE)
with grpc.secure_channel(_SERVER_ADDR_TEMPLATE % port,

@ -19,9 +19,7 @@ from __future__ import print_function
from concurrent import futures
import argparse
import contextlib
import logging
import time
import threading
import grpc
@ -32,7 +30,6 @@ from examples.python.cancellation import hash_name_pb2_grpc
_LOGGER = logging.getLogger(__name__)
_SERVER_HOST = 'localhost'
_ONE_DAY_IN_SECONDS = 60 * 60 * 24
_DESCRIPTION = "A server for finding hashes similar to names."
@ -88,7 +85,6 @@ class HashFinder(hash_name_pb2_grpc.HashFinderServicer):
_LOGGER.debug("Regained servicer thread.")
@contextlib.contextmanager
def _running_server(port, maximum_hashes):
# We use only a single servicer thread here to demonstrate that, if managed
# carefully, cancelled RPCs can need not continue occupying servicers
@ -101,12 +97,7 @@ def _running_server(port, maximum_hashes):
actual_port = server.add_insecure_port(address)
server.start()
print("Server listening at '{}'".format(address))
try:
yield actual_port
except KeyboardInterrupt:
pass
finally:
server.stop(None)
return server
def main():
@ -124,9 +115,8 @@ def main():
nargs='?',
help='The maximum number of hashes to search before cancelling.')
args = parser.parse_args()
with _running_server(args.port, args.maximum_hashes):
while True:
time.sleep(_ONE_DAY_IN_SECONDS)
server = _running_server(args.port, args.maximum_hashes)
server.wait_for_termination()
if __name__ == "__main__":

@ -21,7 +21,6 @@ from concurrent import futures
import argparse
import logging
import threading
import time
import grpc
from examples import helloworld_pb2
@ -36,7 +35,6 @@ _COMPRESSION_OPTIONS = {
_LOGGER = logging.getLogger(__name__)
_SERVER_HOST = 'localhost'
_ONE_DAY_IN_SECONDS = 60 * 60 * 24
class Greeter(helloworld_pb2_grpc.GreeterServicer):
@ -72,11 +70,7 @@ def run_server(server_compression, no_compress_every_n, port):
server.add_insecure_port(address)
server.start()
print("Server listening at '{}'".format(address))
try:
while True:
time.sleep(_ONE_DAY_IN_SECONDS)
except KeyboardInterrupt:
server.stop(None)
server.wait_for_termination()
def main():

@ -19,7 +19,6 @@ from __future__ import print_function
import argparse
import logging
import time
from concurrent import futures
import random
@ -32,7 +31,6 @@ from examples import helloworld_pb2_grpc
_LOGGER = logging.getLogger(__name__)
_LOGGER.setLevel(logging.INFO)
_ONE_DAY_IN_SECONDS = 60 * 60 * 24
_RANDOM_FAILURE_RATE = 0.3
@ -78,11 +76,7 @@ def main():
server = create_server(addr=args.addr, failure_rate=args.failure_rate)
server.start()
try:
while True:
time.sleep(_ONE_DAY_IN_SECONDS)
except KeyboardInterrupt:
server.stop(0)
server.wait_for_termination()
if __name__ == '__main__':

@ -14,7 +14,6 @@
"""This example sends out rich error status from server-side."""
from concurrent import futures
import time
import logging
import threading
@ -27,8 +26,6 @@ from google.rpc import code_pb2, status_pb2, error_details_pb2
from examples import helloworld_pb2
from examples import helloworld_pb2_grpc
_ONE_DAY_IN_SECONDS = 60 * 60 * 24
def create_greet_limit_exceed_error_status(name):
detail = any_pb2.Any()
@ -73,11 +70,7 @@ def create_server(server_address):
def serve(server):
server.start()
try:
while True:
time.sleep(_ONE_DAY_IN_SECONDS)
except KeyboardInterrupt:
server.stop(None)
server.wait_for_termination()
def main():

@ -14,7 +14,6 @@
"""The Python implementation of the GRPC helloworld.Greeter server."""
from concurrent import futures
import time
import logging
import grpc
@ -22,8 +21,6 @@ import grpc
import helloworld_pb2
import helloworld_pb2_grpc
_ONE_DAY_IN_SECONDS = 60 * 60 * 24
class Greeter(helloworld_pb2_grpc.GreeterServicer):
@ -36,11 +33,7 @@ def serve():
helloworld_pb2_grpc.add_GreeterServicer_to_server(Greeter(), server)
server.add_insecure_port('[::]:50051')
server.start()
try:
while True:
time.sleep(_ONE_DAY_IN_SECONDS)
except KeyboardInterrupt:
server.stop(0)
server.wait_for_termination()
if __name__ == '__main__':

@ -14,7 +14,6 @@
"""The reflection-enabled version of gRPC helloworld.Greeter server."""
from concurrent import futures
import time
import logging
import grpc
@ -23,8 +22,6 @@ from grpc_reflection.v1alpha import reflection
import helloworld_pb2
import helloworld_pb2_grpc
_ONE_DAY_IN_SECONDS = 60 * 60 * 24
class Greeter(helloworld_pb2_grpc.GreeterServicer):
@ -42,11 +39,7 @@ def serve():
reflection.enable_server_reflection(SERVICE_NAMES, server)
server.add_insecure_port('[::]:50051')
server.start()
try:
while True:
time.sleep(_ONE_DAY_IN_SECONDS)
except KeyboardInterrupt:
server.stop(0)
server.wait_for_termination()
if __name__ == '__main__':

@ -14,7 +14,6 @@
"""The Python implementation of the GRPC helloworld.Greeter server."""
from concurrent import futures
import time
import logging
import grpc
@ -23,8 +22,6 @@ import helloworld_pb2
import helloworld_pb2_grpc
from request_header_validator_interceptor import RequestHeaderValidatorInterceptor
_ONE_DAY_IN_SECONDS = 60 * 60 * 24
class Greeter(helloworld_pb2_grpc.GreeterServicer):
@ -42,11 +39,7 @@ def serve():
helloworld_pb2_grpc.add_GreeterServicer_to_server(Greeter(), server)
server.add_insecure_port('[::]:50051')
server.start()
try:
while True:
time.sleep(_ONE_DAY_IN_SECONDS)
except KeyboardInterrupt:
server.stop(0)
server.wait_for_termination()
if __name__ == '__main__':

@ -15,7 +15,6 @@
from __future__ import print_function
from concurrent import futures
import time
import logging
import grpc
@ -23,8 +22,6 @@ import grpc
import helloworld_pb2
import helloworld_pb2_grpc
_ONE_DAY_IN_SECONDS = 60 * 60 * 24
class Greeter(helloworld_pb2_grpc.GreeterServicer):
@ -44,11 +41,7 @@ def serve():
helloworld_pb2_grpc.add_GreeterServicer_to_server(Greeter(), server)
server.add_insecure_port('[::]:50051')
server.start()
try:
while True:
time.sleep(_ONE_DAY_IN_SECONDS)
except KeyboardInterrupt:
server.stop(0)
server.wait_for_termination()
if __name__ == '__main__':

@ -26,8 +26,6 @@ import route_guide_pb2
import route_guide_pb2_grpc
import route_guide_resources
_ONE_DAY_IN_SECONDS = 60 * 60 * 24
def _get_feature(feature_db, point):
"""Returns Feature at given location or None."""
@ -129,11 +127,7 @@ def serve():
_RouteGuideServicer(), server)
server.add_insecure_port('[::]:50051')
server.start()
try:
while True:
time.sleep(_ONE_DAY_IN_SECONDS)
except KeyboardInterrupt:
server.stop(0)
server.wait_for_termination()
if __name__ == '__main__':

@ -24,8 +24,6 @@ import route_guide_pb2
import route_guide_pb2_grpc
import route_guide_resources
_ONE_DAY_IN_SECONDS = 60 * 60 * 24
def get_feature(feature_db, point):
"""Returns Feature at given location or None."""
@ -119,11 +117,7 @@ def serve():
RouteGuideServicer(), server)
server.add_insecure_port('[::]:50051')
server.start()
try:
while True:
time.sleep(_ONE_DAY_IN_SECONDS)
except KeyboardInterrupt:
server.stop(0)
server.wait_for_termination()
if __name__ == '__main__':

@ -28,8 +28,6 @@ from examples import helloworld_pb2_grpc
_LOGGER = logging.getLogger(__name__)
_LOGGER.setLevel(logging.INFO)
_ONE_DAY_IN_SECONDS = 60 * 60 * 24
@contextmanager
def get_free_loopback_tcp_port():

@ -16,7 +16,6 @@
import argparse
from concurrent import futures
import logging
import time
import grpc
from src.proto.grpc.testing import test_pb2_grpc
@ -25,7 +24,6 @@ from tests.interop import service
from tests.interop import resources
from tests.unit import test_common
_ONE_DAY_IN_SECONDS = 60 * 60 * 24
logging.basicConfig()
_LOGGER = logging.getLogger(__name__)
@ -55,13 +53,8 @@ def serve():
server.start()
_LOGGER.info('Server serving.')
try:
while True:
time.sleep(_ONE_DAY_IN_SECONDS)
except BaseException as e:
_LOGGER.info('Caught exception "%s"; stopping server...', e)
server.stop(None)
_LOGGER.info('Server stopped; exiting.')
server.wait_for_termination()
_LOGGER.info('Server stopped; exiting.')
if __name__ == '__main__':

Loading…
Cancel
Save