Keep data from dds.DynamicData.DataReader after loan

4 posts / 0 new
Last post
Offline
Last seen: 1 year 2 months ago
Joined: 01/27/2023
Posts: 3
Keep data from dds.DynamicData.DataReader after loan

I am trying to make a wrapper for our developers to use when doing unittests. Like expected, loaded of type "LoanedSample" is lost when going out of function context. What I would like to do is to use the get_dictionary-method, but I cannot get it to work. I have tried doing a deepcopy of the DynamicData-object(Does not work).

Is there a preffered way to get a snapshot of the data, when being a "LoanedSample"?

Offline
Last seen: 1 year 2 months ago
Joined: 01/27/2023
Posts: 3

I forgot to add, this if for rti.connextdds python package. The solution for c/c++ is well documented.

Offline
Last seen: 3 days 18 hours ago
Joined: 04/02/2013
Posts: 195

See https://community.rti.com/forum-topic/python-sequence-memory-management

Also, in 7.1.0 the read/take APIs for DynamicData will change significantly and the regular read/take operations will return copies, not loans.

Offline
Last seen: 1 year 2 months ago
Joined: 01/27/2023
Posts: 3

Thank you alexc for your response. It is good that this will be changed in subsequent versions. We will probably be on the current version for a while as an uplift operation in a big organisation is always a bit cumbersome. When I test your suggested solution, I still remain with the same problem though. Let's share some code: 

--------
def convert_to_deepcopy(indata : dds.DynamicData):
  return dds.DynamicData(indata)

def get_latest_data(pattern : str):
  #A reader based on the pattern is created.
  states = state_reader.take() #Type is 'rti.connextdds.DynamicData.LoanedSamples'
  # states[len(states) - 1].data <--- rti.connextdds.DynamicData
  copy = convert_to_deepcopy(states[len(states) - 1].data)
  #Code fails, the copy is probably returned
return copy

def process_data()
  #For below functions I expect a static data object to be returned.
  data_1 = get_latest_data("dumb_data_pattern_1")
  data_2 = get_latest_data("dumb_data_pattern_2")
  #Data is processed below
 
--------

I would like to get a dict or something similar out of the DynamicData, a deepcopy. Is this possible?