I have a program that needs that writes measures into a bugger that i then flushed into a file every half second. Because I'm using multiple uasyncio coroutines, I cannot simply create a fixed size array/bytearray into which I put my data throughout the half second (I tried). There are two main reasons to that: there is a slight frequency variability from cycle to cycle (so a different number of values to save) and I just want to write the bytearray so I don't want to parse it to remove the empty tail values, also managing the indexing isn't easy...
What I currently do is create an empty global bytearray, then extend it throughout the cycle and finally empty it once it has been written into the file. In this thread viewtopic.php?t=2480, I found an efficient way of clearing the bytearray by doing :
Code: Select all
my_bytearray[::] = b''
My code actually works well but I don't find it elegant and the idea of filling up the RAM with discarded data feels very wrong.