From 867e35a458c717f463e156a116897a38ffb0ef8f Mon Sep 17 00:00:00 2001
From: Ken Payson <kpayson@google.com>
Date: Thu, 16 Mar 2017 11:28:14 -0700
Subject: [PATCH] Initialize GIL at startup

---
 src/python/grpcio/grpc/_cython/cygrpc.pyx | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/src/python/grpcio/grpc/_cython/cygrpc.pyx b/src/python/grpcio/grpc/_cython/cygrpc.pyx
index e1bd046a1a..274b5f1b8a 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)
 
-- 
GitLab