diff --git a/src/python/grpcio/grpc/_channel.py b/src/python/grpcio/grpc/_channel.py index 8bae8a12127..3e8a6b75a9d 100644 --- a/src/python/grpcio/grpc/_channel.py +++ b/src/python/grpcio/grpc/_channel.py @@ -1123,7 +1123,8 @@ class _ChannelCallState(object): self.managed_calls = 0 def __del__(self): - if hasattr(self, 'channel') and self.channel: + if hasattr(self, + 'channel') and self.channel and cygrpc and cygrpc.StatusCode: self.channel.close(cygrpc.StatusCode.cancelled, 'Channel deallocated!')