Esempio n. 1
0
def acquire_lock(lock_name):
    started = time.time()
    while True:
        try:
            os.mkdir(utils.get_dir_name(lock_name))
            break
        except OSError, e:
            if e.errno != errno.EEXIST:
                raise

            if not WAIT_FOR_LOCK or (time.time() - started) >= LOCK_TIMEOUT:
                raise LockedException
            time.sleep(LOCK_DELAY)
Esempio n. 2
0
def release_lock(lock_name):
    # We need to delete the entire tree here due to utils.mail_sent
    shutil.rmtree(utils.get_dir_name(lock_name))