aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/python/grpcio/grpc
diff options
context:
space:
mode:
authorGravatar Lidi Zheng <lidiz@google.com>2018-10-12 10:25:32 -0700
committerGravatar Lidi Zheng <lidiz@google.com>2018-10-14 23:33:58 -0700
commit118e134ded9dba1b509852d0986b9e3427eb498f (patch)
treeb6c545f70418f519e1e4144d2cd447dc219c80a9 /src/python/grpcio/grpc
parent2478ea4289687b7cdfd25a3f836be08f65647896 (diff)
fix Exception throw for invalid channel args
* unit test included * throw ValueError exception from Cython to Python * prevent the deconstruction method from failing when Channel initialization failed
Diffstat (limited to 'src/python/grpcio/grpc')
-rw-r--r--src/python/grpcio/grpc/_channel.py5
-rw-r--r--src/python/grpcio/grpc/_cython/_cygrpc/arguments.pxd.pxi4
-rw-r--r--src/python/grpcio/grpc/_cython/_cygrpc/arguments.pyx.pxi4
3 files changed, 8 insertions, 5 deletions
diff --git a/src/python/grpcio/grpc/_channel.py b/src/python/grpcio/grpc/_channel.py
index 3494c9b15a..eeeb4ddb33 100644
--- a/src/python/grpcio/grpc/_channel.py
+++ b/src/python/grpcio/grpc/_channel.py
@@ -981,4 +981,7 @@ class Channel(grpc.Channel):
# then deletion of this grpc._channel.Channel instance can be made to
# effect closure of the underlying cygrpc.Channel instance.
cygrpc.fork_unregister_channel(self)
- _moot(self._connectivity_state)
+ # This prevent the failed-at-initializing object removal from failing.
+ # Though the __init__ failed, the removal will still trigger __del__.
+ if hasattr(self, "_connectivity_state"):
+ _moot(self._connectivity_state)
diff --git a/src/python/grpcio/grpc/_cython/_cygrpc/arguments.pxd.pxi b/src/python/grpcio/grpc/_cython/_cygrpc/arguments.pxd.pxi
index 6cb1bc0c05..e0e068e452 100644
--- a/src/python/grpcio/grpc/_cython/_cygrpc/arguments.pxd.pxi
+++ b/src/python/grpcio/grpc/_cython/_cygrpc/arguments.pxd.pxi
@@ -32,7 +32,7 @@ cdef class _ArgumentProcessor:
cdef grpc_arg c_argument
- cdef void c(self, argument, grpc_arg_pointer_vtable *vtable, references)
+ cdef void c(self, argument, grpc_arg_pointer_vtable *vtable, references) except *
cdef class _ArgumentsProcessor:
@@ -42,5 +42,5 @@ cdef class _ArgumentsProcessor:
cdef readonly list _references
cdef grpc_channel_args _c_arguments
- cdef grpc_channel_args *c(self, grpc_arg_pointer_vtable *vtable)
+ cdef grpc_channel_args *c(self, grpc_arg_pointer_vtable *vtable) except *
cdef un_c(self)
diff --git a/src/python/grpcio/grpc/_cython/_cygrpc/arguments.pyx.pxi b/src/python/grpcio/grpc/_cython/_cygrpc/arguments.pyx.pxi
index 2239e26b32..b7a4277ff6 100644
--- a/src/python/grpcio/grpc/_cython/_cygrpc/arguments.pyx.pxi
+++ b/src/python/grpcio/grpc/_cython/_cygrpc/arguments.pyx.pxi
@@ -52,7 +52,7 @@ cdef grpc_arg _unwrap_grpc_arg(tuple wrapped_arg):
cdef class _ArgumentProcessor:
- cdef void c(self, argument, grpc_arg_pointer_vtable *vtable, references):
+ cdef void c(self, argument, grpc_arg_pointer_vtable *vtable, references) except *:
key, value = argument
cdef bytes encoded_key = _encode(key)
if encoded_key is not key:
@@ -89,7 +89,7 @@ cdef class _ArgumentsProcessor:
self._argument_processors = []
self._references = []
- cdef grpc_channel_args *c(self, grpc_arg_pointer_vtable *vtable):
+ cdef grpc_channel_args *c(self, grpc_arg_pointer_vtable *vtable) except *:
self._c_arguments.arguments_length = len(self._arguments)
if self._c_arguments.arguments_length == 0:
return NULL