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. 7
      src/python/grpcio/grpc/_server.py

@ -1063,5 +1063,5 @@ class Channel(grpc.Channel):
cygrpc.fork_unregister_channel(self) cygrpc.fork_unregister_channel(self)
# This prevent the failed-at-initializing object removal from failing. # This prevent the failed-at-initializing object removal from failing.
# Though the __init__ failed, the removal will still trigger __del__. # 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) _moot(self._connectivity_state)

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

Loading…
Cancel
Save