I'm using sshfs to run some process on one mashine and store the result on another one.
The command I'm using to mount is sshfs user@host:/rempte/path /local/path
.
The scrip I'm running creates a file with a specific name in a folder inside the mount point if it doesn't already exist, then makes work and finally saves the content. If the file already exists it skips it and goes to the next one. After that it moves on to the next filename.
To spread the work over all CPU cores I'm running as many instances of the process as threads on the CPU.
The Python function is following:
def create(fname):
if os.path.exists(fname):
return True
else:
open(fname, 'a').close()
return False
What happens is that sometimes two or more instances of the script will enter the create
function at the exact same time and end up doing both the same work which is pretty time wasteful.
My question is: is there any way to solve this? either by some kind of parameter for ssh or by some change in my Python code.
Making the script multithreaded is currently outside of my scope.