How to automatically delete temporary folder after simulation using pyFMI?

352 Views Asked by At

I am performing lots of parallel simulations using pyFMI for sensitivity studies. For every simulation pyFMI creates temporary files in /tmp/<username>/JModelica.org/jm_tmp******. These files alone are not very big, but begin to pile up until there is no more space left and the program crashes. Is it possible to delete these files after the simulation finished automatically (maybe there is a pyFMI option I don't see)?

Sadly, the name of the temporary directory is random and I don't know to which process it belongs. I also can't delete the whole directory /tmp/<username>/JModelica.org/ after a simulation finished as other simulations are still running.

1

There are 1 best solutions below

0
On

You can use environment TMPDIR see.: https://docs.python.org/2.7/library/tempfile.html e.g. sim1.py os.environment['TMPDIR'] = 'C:/Temp/RunSim1/' sim2.py os.environment['TMPDIR'] = 'C:/Temp/RunSim2/'