Skip to content

Commit

Permalink
Merge pull request #18456 from jhance/gil-fix
Browse files Browse the repository at this point in the history
Make gil handling in completion queue more robust
  • Loading branch information
lidizheng committed Mar 26, 2019
2 parents 8bbfbec + 3de283c commit 5268858
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/python/grpcio/grpc/_cython/_cygrpc/completion_queue.pyx.pxi
Expand Up @@ -30,19 +30,20 @@ cdef grpc_event _next(grpc_completion_queue *c_completion_queue, deadline):
else:
c_deadline = _timespec_from_time(deadline)

with nogil:
while True:
while True:
with nogil:
c_timeout = gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), c_increment)
if gpr_time_cmp(c_timeout, c_deadline) > 0:
c_timeout = c_deadline

c_event = grpc_completion_queue_next(c_completion_queue, c_timeout, NULL)

if (c_event.type != GRPC_QUEUE_TIMEOUT or
gpr_time_cmp(c_timeout, c_deadline) == 0):
break

# Handle any signals
with gil:
cpython.PyErr_CheckSignals()
# Handle any signals
cpython.PyErr_CheckSignals()
return c_event


Expand Down

0 comments on commit 5268858

Please sign in to comment.