From de075024a7cc19c98e58a5c4e928a53cd3acd74a Mon Sep 17 00:00:00 2001 From: Lidi Zheng Date: Mon, 29 Jun 2020 14:53:07 -0700 Subject: [PATCH] Suppress exceptions from the __del__ of channel object --- src/python/grpcio/grpc/_channel.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/python/grpcio/grpc/_channel.py b/src/python/grpcio/grpc/_channel.py index 3e8a6b75a9d..eff5d1a89c6 100644 --- a/src/python/grpcio/grpc/_channel.py +++ b/src/python/grpcio/grpc/_channel.py @@ -1123,10 +1123,12 @@ class _ChannelCallState(object): self.managed_calls = 0 def __del__(self): - if hasattr(self, - 'channel') and self.channel and cygrpc and cygrpc.StatusCode: + try: self.channel.close(cygrpc.StatusCode.cancelled, 'Channel deallocated!') + except (TypeError, AttributeError) as error: + logging.debug('Channel deallocation failed with: <%s>: %s', + type(error), str(error)) def _run_channel_spin_thread(state):