Make sure Core aware of gevent Cython objects

pull/20891/head
Lidi Zheng 5 years ago
parent ce842ecc31
commit 2817afd4e9
  1. 12
      src/python/grpcio/grpc/_cython/_cygrpc/grpc_gevent.pyx.pxi

@ -32,12 +32,16 @@ def _spawn_greenlet(*args):
cdef class SocketWrapper: cdef class SocketWrapper:
def __cinit__(self): def __cinit__(self):
fork_handlers_and_grpc_init()
self.sockopts = [] self.sockopts = []
self.socket = None self.socket = None
self.c_socket = NULL self.c_socket = NULL
self.c_buffer = NULL self.c_buffer = NULL
self.len = 0 self.len = 0
def __dealloc__(self):
grpc_shutdown_blocking()
cdef grpc_error* socket_init(grpc_custom_socket* socket, int domain) with gil: cdef grpc_error* socket_init(grpc_custom_socket* socket, int domain) with gil:
sw = SocketWrapper() sw = SocketWrapper()
sw.c_socket = socket sw.c_socket = socket
@ -258,10 +262,14 @@ cdef void socket_accept(grpc_custom_socket* socket, grpc_custom_socket* client,
cdef class ResolveWrapper: cdef class ResolveWrapper:
def __cinit__(self): def __cinit__(self):
fork_handlers_and_grpc_init()
self.c_resolver = NULL self.c_resolver = NULL
self.c_host = NULL self.c_host = NULL
self.c_port = NULL self.c_port = NULL
def __dealloc__(self):
grpc_shutdown_blocking()
cdef socket_resolve_async_cython(ResolveWrapper resolve_wrapper): cdef socket_resolve_async_cython(ResolveWrapper resolve_wrapper):
try: try:
res = gevent_socket.getaddrinfo(resolve_wrapper.c_host, resolve_wrapper.c_port) res = gevent_socket.getaddrinfo(resolve_wrapper.c_host, resolve_wrapper.c_port)
@ -298,6 +306,7 @@ cdef grpc_error* socket_resolve(char* host, char* port,
cdef class TimerWrapper: cdef class TimerWrapper:
def __cinit__(self, deadline): def __cinit__(self, deadline):
fork_handlers_and_grpc_init()
self.timer = gevent_hub.get_hub().loop.timer(deadline) self.timer = gevent_hub.get_hub().loop.timer(deadline)
self.event = None self.event = None
@ -314,6 +323,9 @@ cdef class TimerWrapper:
self.event.set() self.event.set()
self.timer.stop() self.timer.stop()
def __dealloc__(self):
grpc_shutdown_blocking()
cdef void timer_start(grpc_custom_timer* t) with gil: cdef void timer_start(grpc_custom_timer* t) with gil:
timer = TimerWrapper(t.timeout_ms / 1000.0) timer = TimerWrapper(t.timeout_ms / 1000.0)
timer.c_timer = t timer.c_timer = t

Loading…
Cancel
Save