Merge pull request #7310 from kpayson64/hold_gil_during_cleanup

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

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

@ -102,5 +102,4 @@ cdef class Channel:
def __dealloc__(self):
if self.c_channel != NULL:
with nogil:
grpc_channel_destroy(self.c_channel)
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)
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
grpc_completion_queue_shutdown(self.c_completion_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)
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)
grpc_completion_queue_destroy(self.c_completion_queue)

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

@ -287,8 +287,7 @@ cdef class ByteBuffer:
def __dealloc__(self):
if self.c_byte_buffer != NULL:
with nogil:
grpc_byte_buffer_destroy(self.c_byte_buffer)
grpc_byte_buffer_destroy(self.c_byte_buffer)
cdef class SslPemKeyCertPair:
@ -420,8 +419,7 @@ 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)
grpc_metadata_array_destroy(&self.c_metadata_array)
def __len__(self):
return self.c_metadata_array.count
@ -530,8 +528,7 @@ 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)
gpr_free(self._received_status_details)
def operation_send_initial_metadata(Metadata metadata, int flags):
cdef Operation op = Operation()

@ -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)
grpc_server_destroy(self.c_server)

Loading…
Cancel
Save