Browse Source

pull this in as it's necessary for my slinke stuff.. I have a

change to make to it..

[git-p4: depot-paths = "//depot/": change = 1375]
main
John-Mark Gurney 15 years ago
parent
commit
3370a7b7ef
1 changed files with 29 additions and 0 deletions
  1. +29
    -0
      filelock.py

+ 29
- 0
filelock.py View File

@@ -0,0 +1,29 @@
import fcntl
import shelve

class FileLock(object):
def __init__(self, fname = None):
self.f = open(fname, 'w+')
self.islocked = False

def exclusivelock(self):
fcntl.flock(self.f.fileno(), fcntl.LOCK_EX)
self.islocked = True

def sharedlock(self):
fcntl.flock(self.f.fileno(), fcntl.LOCK_SH)
self.islocked = True

def unlock(self):
fcntl.flock(self.f.fileno(), fcntl.LOCK_UN)
self.islocked = False

class LockShelve(FileLock, shelve.DbfilenameShelf):
def __init__(self, fname, *args, **kwargs):
FileLock.__init__(self, fname + ".lock")
self.exclusivelock()
try:
shelve.DbfilenameShelf.__init__(self, fname, *args, **kwargs)
except:
self.f.close()
raise

Loading…
Cancel
Save