I am doing scientific programming in python, which requires me to run the same script in parallel with minor parameter tweaks. Also I frequently exit the program with either a keyboard interrupt or an exception being raised.
I'd like to use locks to prevent writing into a directory I may already be working in with another instance of my script. I tried lockfile, and in cases of interrupts/exceptions the lock remains on the directory. Is there any way I could release locks when my program is exiting, both "legally" and due to exceptions/interrupts. I am thinking can I somehow work with the garbage collection routines and add in the provision to unlock the directory?