This question is related to my old one (Safe writing to variable in cython c wrapper within two python processes or distinct memory for python processes)
I have custom class inherited from collections.deque with some additional logic:
from collections import deque
from threading import Lock
class DequeWithLock(deque):
def __init__(self, iterable=(), maxlen=None):
super().__init__(iterable, maxlen)
self.lock = Lock()
def safe_append(self, data):
try:
self.lock.acquire()
self.append(data)
finally:
self.lock.release()
I also have in some sort "main" cdef class named SubscriptionClass
. The strange thing is that everything works fine if I write this class as following:
from dxpyfeed.wrapper.utils.data_class import DequeWithLock as deque
cdef class SubscriptionClass:
cdef dict data
def __init__(self):
self.data = dict()
self.data['data'] = deque()
This code works as expected and even Lock() works as supposed to. However I'd like to get rid of unnecessary dict definition, so I rewrite to code in the following way:
cdef class SubscriptionClass:
cdef object data
def __init__(self):
self.data = deque()
But this throws me a message every time a Cython-function started in another thread tries to use SubscriptionClass.data
and no elements are appended to deque. The message: Exception ignored in: 'path.to.cython.function'
.
I also tried to add cdef dict __dict__
from (Mixing cdef and regular python attributes in cdef class) but this gives me dead kernel.