diff --git a/setup.py b/setup.py index 821fda504af..73af9ebc4af 100644 --- a/setup.py +++ b/setup.py @@ -181,6 +181,7 @@ if "linux" in sys.platform or "darwin" in sys.platform: pymodinit_type = 'PyObject*' if PY3 else 'void' pymodinit = '__attribute__((visibility ("default"))) {}'.format(pymodinit_type) DEFINE_MACROS += (('PyMODINIT_FUNC', pymodinit),) + DEFINE_MACROS += (('GRPC_POSIX_FORK_ALLOW_PTHREAD_ATFORK', 1),) # By default, Python3 distutils enforces compatibility of # c plugins (.so files) with the OSX version Python3 was built with. diff --git a/src/core/lib/iomgr/fork_posix.cc b/src/core/lib/iomgr/fork_posix.cc index a55b3a349a2..f3cfd141b6a 100644 --- a/src/core/lib/iomgr/fork_posix.cc +++ b/src/core/lib/iomgr/fork_posix.cc @@ -81,7 +81,9 @@ void grpc_postfork_child() { void grpc_fork_handlers_auto_register() { if (grpc_fork_support_enabled()) { +#ifdef GRPC_POSIX_FORK_ALLOW_PTHREAD_ATFORK pthread_atfork(grpc_prefork, grpc_postfork_parent, grpc_postfork_child); +#endif // GRPC_POSIX_FORK_ALLOW_PTHREAD_ATFORK } }