@@ -9,3 +9,5 @@ cdef class PyverbsObject(object):
cdef class PyverbsCM(PyverbsObject):
cpdef close(self)
+
+cdef close_weakrefs(iterables)
@@ -12,6 +12,30 @@ LOG_LEVEL=logging.INFO
LOG_FORMAT='[%(levelname)s] %(asctime)s %(filename)s:%(lineno)s: %(message)s'
logging.basicConfig(format=LOG_FORMAT, level=LOG_LEVEL, datefmt='%d %b %Y %H:%M:%S')
+
+cdef close_weakrefs(iterables):
+ """
+ For each iterable element of iterables, pop each element and
+ call its close() method. This method is used when an object is being
+ closed while other objects still hold C references to it; the object
+ holds weakrefs to such other object, and closes them before trying to
+ teardown the C resources.
+ :param iterables: an array of WeakSets
+ :return: None
+ """
+ # None elements can be present if an object's close() was called more
+ # than once (e.g. GC and by another object)
+ for it in iterables:
+ if it is None:
+ continue
+ while True:
+ try:
+ tmp = it.pop()
+ tmp.close()
+ except KeyError: # popping an empty set
+ break
+
+
cdef class PyverbsObject(object):
def __cinit__(self):
@@ -20,28 +44,6 @@ cdef class PyverbsObject(object):
def set_log_level(self, val):
self.logger.setLevel(val)
- def close_weakrefs(self, iterables):
- """
- For each iterable element of iterables, pop each element and
- call its close() method. This method is used when an object is being
- closed while other objects still hold C references to it; the object
- holds weakrefs to such other object, and closes them before trying to
- teardown the C resources.
- :param iterables: an array of WeakSets
- :return: None
- """
- # None elements can be present if an object's close() was called more
- # than once (e.g. GC and by another object)
- for it in iterables:
- if it is None:
- continue
- while True:
- try:
- tmp = it.pop()
- tmp.close()
- except KeyError: # popping an empty set
- break
-
cdef class PyverbsCM(PyverbsObject):
"""
@@ -4,6 +4,7 @@ import weakref
from pyverbs.pyverbs_error import PyverbsError
from pyverbs.base import PyverbsRDMAErrno
+from pyverbs.base cimport close_weakrefs
cimport pyverbs.libibverbs_enums as e
from pyverbs.device cimport Context
from pyverbs.srq cimport SRQ
@@ -35,7 +36,7 @@ cdef class CompChannel(PyverbsCM):
cpdef close(self):
self.logger.debug('Closing completion channel')
- self.close_weakrefs([self.cqs])
+ close_weakrefs([self.cqs])
if self.cc != NULL:
rc = v.ibv_destroy_comp_channel(self.cc)
if rc != 0:
@@ -108,7 +109,7 @@ cdef class CQ(PyverbsCM):
cpdef close(self):
self.logger.debug('Closing CQ')
- self.close_weakrefs([self.qps, self.srqs])
+ close_weakrefs([self.qps, self.srqs])
if self.cq != NULL:
rc = v.ibv_destroy_cq(self.cq)
if rc != 0:
@@ -292,7 +293,7 @@ cdef class CQEX(PyverbsCM):
cpdef close(self):
self.logger.debug('Closing CQEx')
- self.close_weakrefs([self.srqs, self.qps])
+ close_weakrefs([self.srqs, self.qps])
if self.cq != NULL:
rc = v.ibv_destroy_cq(<v.ibv_cq*>self.cq)
if rc != 0:
@@ -12,6 +12,7 @@ from .pyverbs_error import PyverbsRDMAError, PyverbsError
from pyverbs.cq cimport CQEX, CQ, CompChannel
from .pyverbs_error import PyverbsUserError
from pyverbs.base import PyverbsRDMAErrno
+from pyverbs.base cimport close_weakrefs
cimport pyverbs.libibverbs_enums as e
cimport pyverbs.libibverbs as v
from pyverbs.cmid cimport CMID
@@ -144,8 +145,8 @@ cdef class Context(PyverbsCM):
cpdef close(self):
self.logger.debug('Closing Context')
- self.close_weakrefs([self.qps, self.ccs, self.cqs, self.dms, self.pds,
- self.xrcds])
+ close_weakrefs([self.qps, self.ccs, self.cqs, self.dms, self.pds,
+ self.xrcds])
if self.context != NULL:
rc = v.ibv_close_device(self.context)
if rc != 0:
@@ -647,7 +648,7 @@ cdef class DM(PyverbsCM):
cpdef close(self):
self.logger.debug('Closing DM')
- self.close_weakrefs([self.dm_mrs])
+ close_weakrefs([self.dm_mrs])
if self.dm != NULL:
rc = v.ibv_free_dm(self.dm)
if rc != 0:
@@ -4,6 +4,7 @@ import weakref
from pyverbs.pyverbs_error import PyverbsUserError, PyverbsError
from pyverbs.base import PyverbsRDMAErrno
+from pyverbs.base cimport close_weakrefs
from pyverbs.device cimport Context
from libc.stdint cimport uintptr_t
from pyverbs.cmid cimport CMID
@@ -65,8 +66,8 @@ cdef class PD(PyverbsCM):
:return: None
"""
self.logger.debug('Closing PD')
- self.close_weakrefs([self.parent_domains, self.qps, self.ahs, self.mws,
- self.mrs, self.srqs])
+ close_weakrefs([self.parent_domains, self.qps, self.ahs, self.mws,
+ self.mrs, self.srqs])
if self.pd != NULL:
rc = v.ibv_dealloc_pd(self.pd)
if rc != 0:
@@ -4,6 +4,7 @@ import weakref
from pyverbs.pyverbs_error import PyverbsRDMAError, PyverbsError
from pyverbs.base import PyverbsRDMAErrno
+from pyverbs.base cimport close_weakrefs
from pyverbs.device cimport Context
from pyverbs.srq cimport SRQ
from pyverbs.qp cimport QP
@@ -68,7 +69,7 @@ cdef class XRCD(PyverbsCM):
:return: None
"""
self.logger.debug('Closing XRCD')
- self.close_weakrefs([self.qps, self.srqs])
+ close_weakrefs([self.qps, self.srqs])
# XRCD may be deleted directly or indirectly by closing its context,
# which leaves the Python XRCD object without the underlying C object,
# so during destruction, need to check whether or not the C object