Closed joanlopez closed 7 years ago
Can you show the code you are using? Generally you would lock the actual file instead of create a lockfile using this application.
If you require this sort of operation I could easily create a utility function to handle this of course :)
Our project is available here: https://earth.bsc.es/gitlab/es/autosubmit
I think this incoherence is happening because we are not doing the proper usage of the library.
Our tool is intended to run different experiments in different supercomputers (workflow manager). In this case, our experiments are composed by some configuration files, some temporal files, etc.
This is why we are using a fictional .lock
file inside the experiments's folder. For example, to prevent running the same experiment twice at the same time (what could produce internal incoherences).
What could be a proper way of usage for this purpose?
There isn't one I suppose :)
It's a use-case I haven't considered before but I'm implementing a new utility function as we speak which will do the trick for you
I've added a utility class to easily create a temporary lockfile which will always* disappear after unlocking.
You can use it like this:
import portalocker
with portalocker.TemporaryFileLock(optional_filename_here):
# do something here
pass
Or:
import portalocker
lock = portalocker.TemporaryFileLock()
lock.acquire()
# do something here
# the lock automatically gets cleaned when the program exits but manually unlocking is possible:
lock.release()
Can you give it a try?
*when the process is killed using "kill -9" it won't have the chance to cleanup.
Hi,
I'm currently using this library in a Python application.
It is working quite good, but although it works, it does not remove the
.lock
file after the unlock.There's any way/option to do it? The existence of this file while there are no locking processes is quite confusing.
Thanks.