diff --git a/src/python/grpcio/grpc/_cython/cygrpc.pyx b/src/python/grpcio/grpc/_cython/cygrpc.pyx index e1bd046a1a5e72035b5c5efc05defc583bfd6bf1..274b5f1b8ac2cd26ad3a2553689b3a957050ef3c 100644 --- a/src/python/grpcio/grpc/_cython/cygrpc.pyx +++ b/src/python/grpcio/grpc/_cython/cygrpc.pyx @@ -47,14 +47,14 @@ include "_cygrpc/server.pyx.pxi" # # initialize gRPC # - - cdef extern from "Python.h": - int Py_AtExit(void(*func)()) - + int PyEval_InitThreads() -def _initialize(): +cdef _initialize(): + # We have Python callbacks called by c-core threads, this ensures the GIL + # is initialized. + PyEval_InitThreads() grpc_set_ssl_roots_override_callback( <grpc_ssl_roots_override_callback>ssl_roots_override_callback)