Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to share a lock (e.g. a lock file) between R processes?

I have a bunch of different R processes (independently launched from the command line) that all need to load different big files. To avoid clogging the network, I want to add a lock / semaphore, e.g. via a lock file, so that they get their file one after the other. Only one process should be able to acquire the lock, on a standard Linux system.

like image 782
Michael Kuhn Avatar asked Mar 22 '13 09:03

Michael Kuhn


1 Answers

While I couldn't find an R package, there is the Linux command lockfile that can be used:

write("Attempting to get lock", stderr())
system("lockfile /tmp/my_simple_lock")

# Do stuff

write("Releasing lock", stderr())
system("rm -f /tmp/my_simple_lock")
like image 103
Michael Kuhn Avatar answered Sep 22 '22 01:09

Michael Kuhn