diff options
author | kpayson64 <kpayson@google.com> | 2018-06-01 10:42:08 -0700 |
---|---|---|
committer | kpayson64 <kpayson@google.com> | 2018-06-01 10:42:08 -0700 |
commit | b26b2af1dbd88a0b0d5ca6f6e0db5de368757b09 (patch) | |
tree | 819dae67daa43ed087bc8a900a8e8e40f3778fe7 /src/python/grpcio/grpc/_cython/_cygrpc | |
parent | c0a89c71ff7a64aa967a2e4f437eecf0b69af5e7 (diff) | |
parent | 56500bed623aac5d0afecf865cec1f7f5f091fdc (diff) |
Merge remote-tracking branch 'upstream/v1.12.x' into upmerge_changes
Diffstat (limited to 'src/python/grpcio/grpc/_cython/_cygrpc')
-rw-r--r-- | src/python/grpcio/grpc/_cython/_cygrpc/credentials.pyx.pxi | 13 | ||||
-rw-r--r-- | src/python/grpcio/grpc/_cython/_cygrpc/grpc_gevent.pyx | 5 |
2 files changed, 17 insertions, 1 deletions
diff --git a/src/python/grpcio/grpc/_cython/_cygrpc/credentials.pyx.pxi b/src/python/grpcio/grpc/_cython/_cygrpc/credentials.pyx.pxi index 500086f6cb..dff9097bf9 100644 --- a/src/python/grpcio/grpc/_cython/_cygrpc/credentials.pyx.pxi +++ b/src/python/grpcio/grpc/_cython/_cygrpc/credentials.pyx.pxi @@ -17,6 +17,17 @@ cimport cpython import grpc import threading +def _spawn_callback_in_thread(cb_func, args): + threading.Thread(target=cb_func, args=args).start() + +async_callback_func = _spawn_callback_in_thread + +def set_async_callback_func(callback_func): + global async_callback_func + async_callback_func = callback_func + +def _spawn_callback_async(callback, args): + async_callback_func(callback, args) cdef class CallCredentials: @@ -40,7 +51,7 @@ cdef int _get_metadata( else: cb(user_data, NULL, 0, status, error_details) args = context.service_url, context.method_name, callback, - threading.Thread(target=<object>state, args=args).start() + _spawn_callback_async(<object>state, args) return 0 # Asynchronous return diff --git a/src/python/grpcio/grpc/_cython/_cygrpc/grpc_gevent.pyx b/src/python/grpcio/grpc/_cython/_cygrpc/grpc_gevent.pyx index 31ef671aed..f9a1b2856d 100644 --- a/src/python/grpcio/grpc/_cython/_cygrpc/grpc_gevent.pyx +++ b/src/python/grpcio/grpc/_cython/_cygrpc/grpc_gevent.pyx @@ -418,6 +418,11 @@ def init_grpc_gevent(): g_event = gevent.event.Event() g_pool = gevent.pool.Group() + + def cb_func(cb, args): + _spawn_greenlet(cb, *args) + set_async_callback_func(cb_func) + gevent_resolver_vtable.resolve = socket_resolve gevent_resolver_vtable.resolve_async = socket_resolve_async |