Merge pull request #7310 from kpayson64/hold_gil_during_cleanup

Hold onto the GIL in __dealloc__ functions
pull/7225/head
kpayson64 9 years ago committed by GitHub
commit 7be0c97296
  1. 1
      src/python/grpcio/grpc/_cython/_cygrpc/call.pyx.pxi
  2. 1
      src/python/grpcio/grpc/_cython/_cygrpc/channel.pyx.pxi
  3. 6
      src/python/grpcio/grpc/_cython/_cygrpc/completion_queue.pyx.pxi
  4. 3
      src/python/grpcio/grpc/_cython/_cygrpc/credentials.pyx.pxi
  5. 3
      src/python/grpcio/grpc/_cython/_cygrpc/records.pyx.pxi
  6. 1
      src/python/grpcio/grpc/_cython/_cygrpc/server.pyx.pxi

@ -105,7 +105,6 @@ cdef class Call:
def __dealloc__(self):
if self.c_call != NULL:
with nogil:
grpc_call_destroy(self.c_call)
# The object *should* always be valid from Python. Used for debugging.

@ -102,5 +102,4 @@ cdef class Channel:
def __dealloc__(self):
if self.c_channel != NULL:
with nogil:
grpc_channel_destroy(self.c_channel)

@ -118,18 +118,14 @@ cdef class CompletionQueue:
def __dealloc__(self):
cdef gpr_timespec c_deadline
with nogil:
c_deadline = gpr_inf_future(GPR_CLOCK_REALTIME)
if self.c_completion_queue != NULL:
# Ensure shutdown
if not self.is_shutting_down:
with nogil:
grpc_completion_queue_shutdown(self.c_completion_queue)
# Pump the queue
# Pump the queue (All outstanding calls should have been cancelled)
while not self.is_shutdown:
with nogil:
event = grpc_completion_queue_next(
self.c_completion_queue, c_deadline, NULL)
self._interpret_event(event)
with nogil:
grpc_completion_queue_destroy(self.c_completion_queue)

@ -46,7 +46,6 @@ cdef class ChannelCredentials:
def __dealloc__(self):
if self.c_credentials != NULL:
with nogil:
grpc_channel_credentials_release(self.c_credentials)
@ -64,7 +63,6 @@ cdef class CallCredentials:
def __dealloc__(self):
if self.c_credentials != NULL:
with nogil:
grpc_call_credentials_release(self.c_credentials)
@ -76,7 +74,6 @@ cdef class ServerCredentials:
def __dealloc__(self):
if self.c_credentials != NULL:
with nogil:
grpc_server_credentials_release(self.c_credentials)

@ -287,7 +287,6 @@ cdef class ByteBuffer:
def __dealloc__(self):
if self.c_byte_buffer != NULL:
with nogil:
grpc_byte_buffer_destroy(self.c_byte_buffer)
@ -420,7 +419,6 @@ cdef class Metadata:
# this frees the allocated memory for the grpc_metadata_array (although
# it'd be nice if that were documented somewhere...)
# TODO(atash): document this in the C core
with nogil:
grpc_metadata_array_destroy(&self.c_metadata_array)
def __len__(self):
@ -530,7 +528,6 @@ cdef class Operation:
# Python. The remaining one(s) are primitive fields filled in by GRPC core.
# This means that we need to clean up after receive_status_on_client.
if self.c_op.type == GRPC_OP_RECV_STATUS_ON_CLIENT:
with nogil:
gpr_free(self._received_status_details)
def operation_send_initial_metadata(Metadata metadata, int flags):

@ -171,5 +171,4 @@ cdef class Server:
# much but repeatedly release the GIL and wait
while not self.is_shutdown:
time.sleep(0)
with nogil:
grpc_server_destroy(self.c_server)

Loading…
Cancel
Save