2

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.

Yannick
  • 177
  • 1
  • 10
  • If that's an option, you could change the way how these files are created (check the function `create_temp_file` in `src/common/core.py`). Then you could somehow use the filename to keep track of which simulation the file belongs to. – ksbg Sep 20 '18 at 08:29
  • The temporary files should be deleted once the FMU object is garbage collected. Do you keep a reference to the FMU objects for the whole duration of the program? – Christian Winther Sep 21 '18 at 06:31
  • @ksbg: Thank you for pointing me in this direction. It could actually be an option. – Yannick Sep 21 '18 at 09:41
  • @ChristianWinther: I created a class referencing the fmu to perform single simulations. Another class uses this class and starts the simulations in parallel. References are therefore kept for the whole duration of the program. – Yannick Sep 21 '18 at 09:45
  • My current solution checks the age of the directories in `/tmp//JModelica.org/` and deletes occurrences older than a specific limit. – Yannick Sep 21 '18 at 09:48
  • @Yannick Ok, but if you keep a reference to the simulation PyFMI cannot delete the folder (and you should not do it manually either in that case). If you need the reference keep it, but then you should not delete the folders. If you don't need it, delete the reference and the folders will be automatically deleted. – Christian Winther Sep 21 '18 at 18:17
  • @ChristianWinther I just prepared a test and created a small Python script. In the script a single simulation is performed and the result printed to the console. It is my understanding that after the script finished, the directory in `/tmp` should be deleted, but it is still there. – Yannick Sep 22 '18 at 09:58
  • @Yannick, the directory /tmp//JModelica.org will still be there. It is the folders inside the JModelica.org that should be removed, are they? – Christian Winther Oct 03 '18 at 06:57
  • @ChristianWinther thats what I meant: The folders inside `/tmp//JModelica.org` are still there. They are not deleted. – Yannick Oct 14 '18 at 07:08

1 Answers1

0

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/'

Vital
  • 41
  • 3