python fork shutdown to wait briefly

pull/36873/head
Yousuk Seung 8 months ago
parent fabf135c7f
commit 7908a6912a
  1. 16
      src/python/grpcio/grpc/_cython/_cygrpc/fork_posix.pyx.pxi

@ -79,11 +79,15 @@ cdef void __postfork_child() noexcept nogil:
_LOGGER.error('Exiting child due to raised exception')
_LOGGER.error(sys.exc_info()[0])
os._exit(os.EX_USAGE)
if grpc_is_initialized() > 0:
with gil:
_LOGGER.error('Failed to shutdown gRPC Core after fork()')
os._exit(os.EX_USAGE)
# Give ~2s to shutdown asynchronously.
wait_ms = 10
while wait_ms < 1500:
if grpc_is_initialized() == 0:
return
time.sleep(wait_ms / 1000)
wait_ms = wait_ms * 2
_LOGGER.error('Failed to shutdown gRPC Core after fork()')
os._exit(os.EX_USAGE)
def fork_handlers_and_grpc_init():
@ -153,7 +157,7 @@ def get_fork_epoch():
def is_fork_support_enabled():
return _GRPC_ENABLE_FORK_SUPPORT
def fork_register_channel(channel):
if _GRPC_ENABLE_FORK_SUPPORT:
_fork_state.channels.add(channel)

Loading…
Cancel
Save