aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/python/grpcio
diff options
context:
space:
mode:
authorGravatar Nathaniel Manista <nathaniel@google.com>2016-07-07 21:06:17 +0000
committerGravatar Nathaniel Manista <nathaniel@google.com>2016-07-07 21:06:17 +0000
commita6b2a5a090ff057f77976b22d854ff375883c1b9 (patch)
treeabcffe642b3708dae079442638edec36cb096a4d /src/python/grpcio
parent8fddced6cbe0fd4636a7b528560396c375fb7e29 (diff)
Make handlers optional at server construction
Diffstat (limited to 'src/python/grpcio')
-rw-r--r--src/python/grpcio/grpc/__init__.py16
-rw-r--r--src/python/grpcio/grpc/_server.py2
-rw-r--r--src/python/grpcio/grpc/beta/_server_adaptations.py3
3 files changed, 10 insertions, 11 deletions
diff --git a/src/python/grpcio/grpc/__init__.py b/src/python/grpcio/grpc/__init__.py
index b3eeaad1f7..f7d51d2df7 100644
--- a/src/python/grpcio/grpc/__init__.py
+++ b/src/python/grpcio/grpc/__init__.py
@@ -1207,25 +1207,23 @@ def secure_channel(target, credentials, options=None):
return _channel.Channel(target, options, credentials._credentials)
-def server(generic_rpc_handlers, thread_pool, options=None):
+def server(thread_pool, handlers=None):
"""Creates a Server with which RPCs can be serviced.
- The GenericRpcHandlers passed to this function needn't be the only
- GenericRpcHandlers that will be used to serve RPCs; others may be added later
- by calling add_generic_rpc_handlers any time before the returned server is
- started.
-
Args:
- generic_rpc_handlers: Some number of GenericRpcHandlers that will be used
- to service RPCs after the returned Server is started.
thread_pool: A futures.ThreadPoolExecutor to be used by the returned Server
to service RPCs.
+ handlers: An optional sequence of GenericRpcHandlers to be used to service
+ RPCs after the returned Server is started. These handlers need not be the
+ only handlers the returned Server will use to service RPCs; other
+ handlers may later be added to the returned Server by calling its
+ add_generic_rpc_handlers method any time before it is started.
Returns:
A Server with which RPCs can be serviced.
"""
from grpc import _server
- return _server.Server(generic_rpc_handlers, thread_pool)
+ return _server.Server(thread_pool, () if handlers is None else handlers)
################################### __all__ #################################
diff --git a/src/python/grpcio/grpc/_server.py b/src/python/grpcio/grpc/_server.py
index f4c114056f..f8a9d5afd3 100644
--- a/src/python/grpcio/grpc/_server.py
+++ b/src/python/grpcio/grpc/_server.py
@@ -731,7 +731,7 @@ def _start(state):
class Server(grpc.Server):
- def __init__(self, generic_handlers, thread_pool):
+ def __init__(self, thread_pool, generic_handlers):
completion_queue = cygrpc.CompletionQueue()
server = cygrpc.Server()
server.register_completion_queue(completion_queue)
diff --git a/src/python/grpcio/grpc/beta/_server_adaptations.py b/src/python/grpcio/grpc/beta/_server_adaptations.py
index 1e1f80156a..cca4a1797a 100644
--- a/src/python/grpcio/grpc/beta/_server_adaptations.py
+++ b/src/python/grpcio/grpc/beta/_server_adaptations.py
@@ -371,4 +371,5 @@ def server(
_DEFAULT_POOL_SIZE if thread_pool_size is None else thread_pool_size)
else:
effective_thread_pool = thread_pool
- return _Server(grpc.server((generic_rpc_handler,), effective_thread_pool))
+ return _Server(
+ grpc.server(effective_thread_pool, handlers=(generic_rpc_handler,)))