Merge pull request #17699 from ericgribkoff/check_state_backport

avoid AttributeError when object init fails
pull/17712/head
Eric Gribkoff 6 years ago committed by GitHub
commit 704ee7a03c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  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)
# 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,9 +860,10 @@ class _Server(grpc.Server):
return _stop(self._state, grace)
def __del__(self):
# 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
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
def create_server(thread_pool, generic_rpc_handlers, interceptors, options,

Loading…
Cancel
Save