Example #1
0
    def testrecursivelock(self):
        state = teststate(tempfile.mkdtemp(dir=os.getcwd()))
        lock = state.makelock()
        state.assertacquirecalled(self, True)

        state.resetacquirefn()
        lock.lock()
        # recursive lock should not call acquirefn again
        state.assertacquirecalled(self, False)

        lock.release()  # brings lock refcount down from 2 to 1
        state.assertreleasecalled(self, False)
        state.assertpostreleasecalled(self, False)
        state.assertlockexists(self, True)

        lock.release()  # releases the lock
        state.assertreleasecalled(self, True)
        state.assertpostreleasecalled(self, True)
        state.assertlockexists(self, False)
Example #2
0
    def testrecursivelock(self):
        state = teststate(self, tempfile.mkdtemp(dir=os.getcwd()))
        lock = state.makelock()
        state.assertacquirecalled(True)

        state.resetacquirefn()
        lock.lock()
        # recursive lock should not call acquirefn again
        state.assertacquirecalled(False)

        lock.release()  # brings lock refcount down from 2 to 1
        state.assertreleasecalled(False)
        state.assertpostreleasecalled(False)
        state.assertlockexists(True)

        lock.release()  # releases the lock
        state.assertreleasecalled(True)
        state.assertpostreleasecalled(True)
        state.assertlockexists(False)
Example #3
0
def lock():
    global _lockref

    l = _lockref and _lockref()
    if l is not None and l.held:
        l.lock()
        return l

    l = lockmod.lock("/tmp/patchwork.parsemail.lock", timeout=60)
    _lockref = weakref.ref(l)
    return l
Example #4
0
def lock():
    global _lockref

    l = _lockref and _lockref()
    if l is not None and l.held:
        l.lock()
        return l

    l = lockmod.lock("/tmp/patchwork.parsemail.lock", timeout=30)
    _lockref = weakref.ref(l)
    return l
Example #5
0
def lock():
    global _lockref

    lk = _lockref and _lockref()
    if lk is not None and lk.held:
        lk.lock()
        return lk

    lk = lockmod.lock("/tmp/patchwork.parsemail.lock", timeout=60)
    _lockref = weakref.ref(lk)
    return lk