Bill-Gray / find_orb

Orbit determination from observations
https://www.projectpluto.com/find_orb.htm
GNU General Public License v2.0
97 stars 45 forks source link

Use mktemp to generate temp_obs files #28

Closed moeyensj closed 3 years ago

moeyensj commented 3 years ago

While working on multiprocessing the fo Python subprocess wrappers, I was getting errors that the /tmp/mpc_obs.txt file was missing for some of the concurrently running processes. It turns out each fo process was working on the same temporary observation file which was causing issues.

Here is an example from my Python wrapper, the second statement is a stderr output from fo:

(pid=135436) Find_Orb call complete.
(pid=135436) Couldn't locate the file '/tmp/temp_obs.txt'

This PR contains a relatively simple fix to randomly generate a temp_obs file using a template string. This fix avoids the issue with multiple threads working on the sample temporary file. I have tested the change on my multiprocessed wrapper and thus far have not encountered any more issues.

Note: the compiler now warns that using mkstemp is better than mktemp. From my understanding of the code, swapping to mkstemp would involve making more changes than I am comfortable making (mkstemp creates the temporary file while mktemp creates the file's name).

Bill-Gray commented 3 years ago

Gah, thought I'd pulled this already... thanks!

Bill-Gray commented 3 years ago

I see what you mean about mktemp() vs mkstemp(). Should get time to fix that later today, I hope.