05-11-2021, 02:05 PM
Hi Tim
I was using up arrow to repeat the command, and the file was empty three times, so it was probably empty for around a second. Because the file is opened for writing before the data is collected, maybe some of the data collection/processing is taking longer than expected (maybe interupted by another process) and the file then has zero length for longer than expected (I am on a Pi Zero with not much CPU headroom).
Regarding the implementation, it might avoid access issues if the file was written to another name and then renamed to currentsong.txt afterwards. (The zero-length window could be reduced by opening the file for writing after the data is collected, but the rename should avoid the empty file altogether.)
Adrian.
I was using up arrow to repeat the command, and the file was empty three times, so it was probably empty for around a second. Because the file is opened for writing before the data is collected, maybe some of the data collection/processing is taking longer than expected (maybe interupted by another process) and the file then has zero length for longer than expected (I am on a Pi Zero with not much CPU headroom).
Regarding the implementation, it might avoid access issues if the file was written to another name and then renamed to currentsong.txt afterwards. (The zero-length window could be reduced by opening the file for writing after the data is collected, but the rename should avoid the empty file altogether.)
Adrian.