diff options
-rw-r--r-- | src/python/grpcio/grpc/_cython/cygrpc.pyx | 9 | ||||
-rw-r--r-- | src/python/grpcio/grpc/_cython/loader.c | 3 |
2 files changed, 10 insertions, 2 deletions
diff --git a/src/python/grpcio/grpc/_cython/cygrpc.pyx b/src/python/grpcio/grpc/_cython/cygrpc.pyx index e055d321bc..2fc8e16461 100644 --- a/src/python/grpcio/grpc/_cython/cygrpc.pyx +++ b/src/python/grpcio/grpc/_cython/cygrpc.pyx @@ -49,6 +49,11 @@ include "grpc/_cython/_cygrpc/server.pyx.pxi" # +cdef extern from "Python.h": + + int Py_AtExit(void(*func)()) + + def _initialize(): if not pygrpc_initialize_core(): raise ImportError('failed to initialize core gRPC library') @@ -56,4 +61,8 @@ def _initialize(): grpc_set_ssl_roots_override_callback( <grpc_ssl_roots_override_callback>ssl_roots_override_callback) + if Py_AtExit(grpc_shutdown) != 0: + raise ImportError('failed to register gRPC library shutdown callbacks') + + _initialize() diff --git a/src/python/grpcio/grpc/_cython/loader.c b/src/python/grpcio/grpc/_cython/loader.c index 34bd897549..4698f0aff8 100644 --- a/src/python/grpcio/grpc/_cython/loader.c +++ b/src/python/grpcio/grpc/_cython/loader.c @@ -31,7 +31,6 @@ * */ -#include <Python.h> #include "loader.h" #ifdef __cplusplus @@ -43,7 +42,7 @@ int pygrpc_load_core(char *path) { return 1; } // Cython doesn't have Py_AtExit bindings, so we call the C_API directly int pygrpc_initialize_core(void) { grpc_init(); - return Py_AtExit(grpc_shutdown) < 0 ? 0 : 1; + return 1; } #ifdef __cplusplus |