AFAIK this code can be used to lock a directory:
class LockDirectory(object):
def __init__(self, directory):
assert os.path.exists(directory)
I would suggest you go with a simple lock file. As the question in the comment (How to lock a directory between python processes in linux?) suggests, there is no locking mechanism for directories, as opposed to files.
Lock files are used left and right on Linux, they are very transparent and easy to debug, so I would just go with that.
I am waiting to be challenged on this however!