Mar-07-2022, 02:39 PM
I have a problem and have no idea how to solve it. So I have n-threads to download data via bluetooth. This data has to go through a handler which unfortunately runs in a new thread of its own, the handler makes its call in C++ to an API. In this handler I want to count up an index. I'm currently trying with threading.local, but that doesn't work because of the new thread that is automatically created. Can anyone help me?
def data_downloader(...): points = threading.local() point.x = 0 t = np.zeros((n)) data = np.zeros((n, 3)) def handler(p): t[point.x] = p.contents.epoch data[point.x] = parse_value(p) point.x += 1 # unfortunately, they don't add up here callback = FnVoid_VoidP_DataP(lambda ctx, p: handler(p)) # casts the handler to a c++ handler get_data(..., callback) # the data is downloaded here, afterwards the data is processed by the handleredit: Python version is 3.7