mirror of
https://github.com/capnproto/pycapnp.git
synced 2025-03-04 00:14:45 +01:00
Manually handle deallocation of some objects for the benefit of p3.7
Python 3.7 seems to have trouble dealocating objects in a timely fashion. We rely on this, because the c++ destructors need to run before the kj event loop is closed. Hence, we do it manually.
This commit is contained in:
parent
74ebaff4e3
commit
d6261b6d79
1 changed files with 20 additions and 0 deletions
|
@ -2039,6 +2039,11 @@ cdef class _DynamicCapabilityClient:
|
|||
cdef C_DynamicCapability.Client thisptr
|
||||
cdef public object _parent, _cached_schema
|
||||
|
||||
def __dealloc__(self):
|
||||
# Needed to make Python 3.7 happy, which seems to have trouble deallocating stack objects
|
||||
# appropriately
|
||||
self.thisptr = C_DynamicCapability.Client()
|
||||
|
||||
cdef _init(self, C_DynamicCapability.Client other, object parent):
|
||||
self.thisptr = other
|
||||
self._parent = parent
|
||||
|
@ -2194,6 +2199,11 @@ cdef class TwoPartyClient:
|
|||
cdef Own[RpcSystem] thisptr
|
||||
cdef _TwoPartyVatNetwork _network
|
||||
|
||||
def __dealloc__(self):
|
||||
# Needed to make Python 3.7 happy, which seems to have trouble deallocating stack objects
|
||||
# appropriately
|
||||
self.thisptr = Own[RpcSystem]()
|
||||
|
||||
def __init__(self, socket=None, traversal_limit_in_words=None, nesting_limit=None):
|
||||
|
||||
cdef schema_cpp.ReaderOptions opts = make_reader_opts(traversal_limit_in_words, nesting_limit)
|
||||
|
@ -2224,6 +2234,11 @@ cdef class TwoPartyServer:
|
|||
cdef Own[RpcSystem] thisptr
|
||||
cdef _TwoPartyVatNetwork _network
|
||||
|
||||
def __dealloc__(self):
|
||||
# Needed to make Python 3.7 happy, which seems to have trouble deallocating stack objects
|
||||
# appropriately
|
||||
self.thisptr = Own[RpcSystem]()
|
||||
|
||||
def __init__(self, socket=None, bootstrap=None, traversal_limit_in_words=None, nesting_limit=None):
|
||||
if not bootstrap:
|
||||
raise KjException("You must provide a bootstrap interface to a server constructor.")
|
||||
|
@ -2250,6 +2265,11 @@ cdef class _AsyncIoStream:
|
|||
cdef Own[AsyncIoStream] thisptr
|
||||
cdef _EventLoop _event_loop # We hold a pointer to the event loop here, to ensure it remains alive
|
||||
|
||||
def __dealloc__(self):
|
||||
# Needed to make Python 3.7 happy, which seems to have trouble deallocating stack objects
|
||||
# appropriately
|
||||
self.thisptr = Own[AsyncIoStream]()
|
||||
|
||||
@staticmethod
|
||||
async def create_connection(host = None, port = None, **kwargs):
|
||||
"""Create a TCP connection.
|
||||
|
|
Loading…
Add table
Reference in a new issue