diff options
author | Elmo Todurov <elmo.todurov@skype.net> | 2013-06-27 19:21:47 +0300 |
---|---|---|
committer | Elmo Todurov <elmo.todurov@skype.net> | 2013-08-27 11:41:02 +0300 |
commit | e80eeddef17cf92d8c3974b491d5001377f8eff8 (patch) | |
tree | d36fbbbe4fb4090d5b8e5762da753bbbf66f0b1f | |
parent | 379fa0b6131995f96f5bd048906fc0bd3c2527f7 (diff) | |
download | lockfile-e80eeddef17cf92d8c3974b491d5001377f8eff8.tar.gz |
Bugfix: locking two different files in the same directory caused an error during unlocking the last unlocking
-rw-r--r-- | lockfile/__init__.py | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/lockfile/__init__.py b/lockfile/__init__.py index 668b426..d905af9 100644 --- a/lockfile/__init__.py +++ b/lockfile/__init__.py @@ -174,10 +174,19 @@ class LockBase: else: self.tname = "" dirname = os.path.dirname(self.lock_file) + + # unique name is mostly about the current process, but must + # also contain the path -- otherwise, two adjacent locked + # files conflict (one file gets locked, creating lock-file and + # unique file, the other one gets locked, creating lock-file + # and overwriting the already existing lock-file, then one + # gets unlocked, deleting both lock-file and unique file, + # finally the last lock errors out upon releasing. self.unique_name = os.path.join(dirname, - "%s%s.%s" % (self.hostname, - self.tname, - self.pid)) + "%s%s.%s%s" % (self.hostname, + self.tname, + self.pid, + hash(self.path))) self.timeout = timeout def acquire(self, timeout=None): |