avoid AttributeError when object init fails

pull/17699/head
Eric Gribkoff 6 years ago
parent e6454077a3
commit 09f72a1057
  1. 2
      src/python/grpcio/grpc/_channel.py
  2. 1
      src/python/grpcio/grpc/_server.py

@ -1063,5 +1063,5 @@ class Channel(grpc.Channel):
cygrpc.fork_unregister_channel(self)
# This prevent the failed-at-initializing object removal from failing.
# Though the __init__ failed, the removal will still trigger __del__.
if _moot is not None and hasattr(self, "_connectivity_state"):
if _moot is not None and hasattr(self, '_connectivity_state'):
_moot(self._connectivity_state)

@ -860,6 +860,7 @@ class _Server(grpc.Server):
return _stop(self._state, grace)
def __del__(self):
if hasattr(self, '_state'):
# We can not grab a lock in __del__(), so set a flag to signal the
# serving daemon thread (if it exists) to initiate shutdown.
self._state.server_deallocated = True

Loading…
Cancel
Save