3 from __future__ import with_statement
12 def synchronized(lock):
14 Synchronization decorator.
17 >>> misc.validate_decorator(synchronized(object()))
23 def newFunction(*args, **kw):
33 @contextlib.contextmanager
34 def qlock(queue, gblock = True, gtimeout = None, pblock = True, ptimeout = None):
36 Locking with a queue, good for when you want to lock an item passed around
40 >>> lock = Queue.Queue()
42 >>> with qlock(lock) as i:
46 item = queue.get(gblock, gtimeout)
50 queue.put(item, pblock, ptimeout)
53 @contextlib.contextmanager
54 def flock(path, timeout=-1):
61 while timeSpent <= timeout or timeout == WAIT_FOREVER:
63 fd = os.open(path, os.O_CREAT | os.O_EXCL | os.O_RDWR)
67 if e.errno != errno.EEXIST:
72 assert acquired, "Failed to grab file-lock %s within timeout %d" % (path, timeout)