I have a Python script to simulate particle dynamics. The simulations are long (can take up to a month). I save my data with a given frequency. Unfortunately, I had to kill the simulations, and lost a lot of information that I sample at the very end of the simulation, when the main loop is done and the number of simulation steps exhausted.
I would like to know if there is a way in Python to save my last configuration if the work gets killed. That is, if I write in the terminal
killall python
or
kill (id number of the job)
can I trigger something so that my last system configuration gets saved in a file? Can the same be done if some error arises?