I am working with an API that uses a callback function to send data for up to 2000 times per second. The body of the function gets the data argument (that the API calls the function using), appends a timestamp (using datetime.now().timestamp()) to it, then sends it to a queue, where it will be saved in a file after the acquisition has been finished.
The issue I am facing is that I am getting the same timestamps several times, with different data. Below is an example of some of the saved data:
Data------timestamp
3258 1595943590.058758
3246 1595943590.058758
3246 1595943590.058758
3248 1595943590.058758
3254 1595943590.058758
3246 1595943590.058758
I tried using time.time() instead and the issue was still there:
2986 1595944140.3182354
2986 1595944140.3182354
2984 1595944140.3182354
2984 1595944140.3182354
2984 1595944140.3182354
2986 1595944140.3182354
2986 1595944140.3182354
2982 1595944140.3182354
2980 1595944140.3182354
2986 1595944140.3182354
Is the issue that the API is sending data so fast that the time isnt updating fast enough? Is there a more accurate way to get time?
#part of a class
def apiFunc(self, data):
if data:
d = (data, time.time())
self.storage.put(d)
return True
return False