From e9b90e5e1f8183fd0259ae8ccc9735fb8027fe20 Mon Sep 17 00:00:00 2001 From: Masood Malekghassemi Date: Wed, 13 Jul 2016 16:57:31 -0700 Subject: Move Python.h include out of loader code To make a certain private code base work in a certain way nicer than the current way. --- src/python/grpcio/grpc/_cython/cygrpc.pyx | 9 +++++++++ src/python/grpcio/grpc/_cython/loader.c | 3 +-- 2 files changed, 10 insertions(+), 2 deletions(-) (limited to 'src/python/grpcio') 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( 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 #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 -- cgit v1.2.3