insarlab / PySolid

A Python wrapper for solid Earth tides
GNU General Public License v3.0
61 stars 7 forks source link

bug: same `solid.txt` filename conflicts with multi-threads run #50

Closed yunjunz closed 1 year ago

yunjunz commented 1 year ago

A bug found with a solution suggested by @fastice:

I ran into a problem with pysolid.calc_solid_earth_tides_grid().

Basically I am running multiple threads at the same time from the same directory, which means that the individual threads are overwriting or deleting the solid.txt file.

As simple fix so that files from multiple threads would not conflict would be to make the file names unique with something like.

import uuid

txt_file = os.path.abspath(f’solid.{uuid.uuid1().hex}.txt')
if os.path.isfile(txt_file):
  os.remove(txt_file)

No need to change soon on my account, I found a workaround but others might run into a similar problem in a production environment.

This unique TXT filename should be passed to the Fortran code directly as a function argument.