Program not saving data

I have several programs running currently. The programs are running 24/7 so the animals can work whenever they choose. Overall, the programs are working quite well. Not incredibly often, but occasionally, the programs will crash or need to be force quit. When this happens, there is no data file, which is very problematic for me. The program will run without issues for several hours and the participants will do thousands of trials which are all now lost. I don’t see why psychopy would not create a data file if the program crashes or is forced quit? This has not been an issue for me in python or visual basics. Does psychopy wait to write the data files until it is closed? Is there a way to change this so the data file is created at the beginning and writes the information I have added after each trial?

Thanks in advance for any suggestions or information!