Esempio n. 1
0
def lock_dir_until_exit(dir_path):
    """Lock the directory at dir_path until program exit.

    :param str dir_path: path to directory

    :raises errors.LockError: if the lock is held by another process

    """
    if not _LOCKS:  # this is the first lock to be released at exit
        atexit_register(_release_locks)

    if dir_path not in _LOCKS:
        _LOCKS[dir_path] = lock.lock_dir(dir_path)
Esempio n. 2
0
def lock_dir_until_exit(dir_path):
    """Lock the directory at dir_path until program exit.

    :param str dir_path: path to directory

    :raises errors.LockError: if the lock is held by another process

    """
    if not _LOCKS:  # this is the first lock to be released at exit
        atexit_register(_release_locks)

    if dir_path not in _LOCKS:
        _LOCKS[dir_path] = lock.lock_dir(dir_path)
Esempio n. 3
0
def test_command(command, directories):
    """Assert Certbot acquires locks in a specific order.

    command is run repeatedly testing that Certbot acquires locks on
    directories in the order they appear in the parameter directories.

    :param list command: Certbot command to execute
    :param list directories: list of directories Certbot should fail
        to acquire the lock on in sorted order

    """
    locks = [lock.lock_dir(directory) for directory in directories]
    for dir_path, dir_lock in zip(directories, locks):
        check_error(command, dir_path)
        dir_lock.release()
Esempio n. 4
0
def test_command(command, directories):
    """Assert Certbot acquires locks in a specific order.

    command is run repeatedly testing that Certbot acquires locks on
    directories in the order they appear in the parameter directories.

    :param list command: Certbot command to execute
    :param list directories: list of directories Certbot should fail
        to acquire the lock on in sorted order

    """
    locks = [lock.lock_dir(directory) for directory in directories]
    for dir_path, dir_lock in zip(directories, locks):
        check_error(command, dir_path)
        dir_lock.release()
Esempio n. 5
0
def hold_lock(cv, lock_path):  # pragma: no cover
    """Acquire a file lock at lock_path and wait to release it.

    :param multiprocessing.Condition cv: condition for synchronization
    :param str lock_path: path to the file lock

    """
    from certbot import lock
    if os.path.isdir(lock_path):
        my_lock = lock.lock_dir(lock_path)
    else:
        my_lock = lock.LockFile(lock_path)
    cv.acquire()
    cv.notify()
    cv.wait()
    my_lock.release()
Esempio n. 6
0
def hold_lock(cv, lock_path):  # pragma: no cover
    """Acquire a file lock at lock_path and wait to release it.

    :param multiprocessing.Condition cv: condition for synchronization
    :param str lock_path: path to the file lock

    """
    from certbot import lock
    if os.path.isdir(lock_path):
        my_lock = lock.lock_dir(lock_path)
    else:
        my_lock = lock.LockFile(lock_path)
    cv.acquire()
    cv.notify()
    cv.wait()
    my_lock.release()
Esempio n. 7
0
def _handle_lock(event_in, event_out, path):
    """
    Acquire a file lock on given path, then wait to release it. This worker is coordinated
    using events to signal when the lock should be acquired and released.
    :param multiprocessing.Event event_in: event object to signal when to release the lock
    :param multiprocessing.Event event_out: event object to signal when the lock is acquired
    :param path: the path to lock
    """
    if os.path.isdir(path):
        my_lock = lock.lock_dir(path)
    else:
        my_lock = lock.LockFile(path)
    try:
        event_out.set()
        assert event_in.wait(timeout=20), 'Timeout while waiting to release the lock.'
    finally:
        my_lock.release()
Esempio n. 8
0
def _handle_lock(event_in, event_out, path):
    """
    Acquire a file lock on given path, then wait to release it. This worker is coordinated
    using events to signal when the lock should be acquired and released.
    :param multiprocessing.Event event_in: event object to signal when to release the lock
    :param multiprocessing.Event event_out: event object to signal when the lock is acquired
    :param path: the path to lock
    """
    if os.path.isdir(path):
        my_lock = lock.lock_dir(path)
    else:
        my_lock = lock.LockFile(path)
    try:
        event_out.set()
        assert event_in.wait(
            timeout=20), 'Timeout while waiting to release the lock.'
    finally:
        my_lock.release()
Esempio n. 9
0
 def _call(cls, *args, **kwargs):
     from certbot.lock import lock_dir
     return lock_dir(*args, **kwargs)
Esempio n. 10
0
 def _call(cls, *args, **kwargs):
     from certbot.lock import lock_dir
     return lock_dir(*args, **kwargs)