예제 #1
0
def test_can_release_filelock_multiple_times(tmpdir):
    filename = os.path.join(str(tmpdir), 'lock')
    lock = FileLock(filename, timeout=0.01, poll=0.01)
    lock.release()
    lock.acquire()
    lock.release()
    lock.release()
예제 #2
0
def test_can_release_filelock_multiple_times(tmp_path):
    filename = tmp_path / "lock"
    lock = FileLock(filename, timeout=0.01, poll=0.01)
    lock.release()
    lock.acquire()
    lock.release()
    lock.release()
예제 #3
0
def test_released_filelock_can_be_reacquired(tmpdir):
    filename = os.path.join(str(tmpdir), 'lock')
    lock = FileLock(filename, timeout=0.01, poll=0.01)
    lock.acquire()
    lock.release()
    lock.acquire()
    lock.release()
예제 #4
0
def test_released_filelock_can_be_reacquired(tmp_path):
    filename = tmp_path / "lock"
    lock = FileLock(filename, timeout=0.01, poll=0.01)
    lock.acquire()
    lock.release()
    lock.acquire()
    lock.release()
예제 #5
0
파일: test_lock.py 프로젝트: weizx208/nengo
def test_filelock_gets_released_on_lock_deletion(tmpdir):
    filename = os.path.join(str(tmpdir), 'lock')
    lock = FileLock(filename, timeout=0.01, poll=0.01)
    lock.acquire()
    del lock
    lock = FileLock(filename, timeout=0.01, poll=0.01)
    lock.acquire()
    lock.release()
예제 #6
0
파일: test_lock.py 프로젝트: weizx208/nengo
def acquire_lock(filename):
    lock = FileLock(filename, timeout=0.01, poll=0.01)
    try:
        lock.acquire()
    except TimeoutError:
        sys.exit(0)
    else:
        sys.exit(1)
예제 #7
0
def test_filelock_gets_released_on_lock_deletion(tmpdir):
    filename = os.path.join(str(tmpdir), 'lock')
    lock = FileLock(filename, timeout=0.01, poll=0.01)
    lock.acquire()
    del lock
    lock = FileLock(filename, timeout=0.01, poll=0.01)
    lock.acquire()
    lock.release()
예제 #8
0
파일: test_lock.py 프로젝트: nengo/nengo
def acquire_lock(filename):
    lock = FileLock(filename, timeout=0.01, poll=0.01)
    try:
        lock.acquire()
    except TimeoutError:
        sys.exit(0)
    else:
        sys.exit(1)
예제 #9
0
def test_filelock_gets_released_on_lock_deletion(tmp_path):
    filename = tmp_path / "lock"
    lock = FileLock(filename, timeout=0.01, poll=0.01)
    lock.acquire()
    del lock
    lock = FileLock(filename, timeout=0.01, poll=0.01)
    lock.acquire()
    lock.release()
예제 #10
0
파일: test_lock.py 프로젝트: weizx208/nengo
def test_can_acquire_filelock_at_most_once(tmpdir):
    filename = os.path.join(str(tmpdir), 'lock')
    lock = FileLock(filename, timeout=0.01, poll=0.01)
    lock.acquire()
    p = multiprocessing.Process(target=acquire_lock, args=(filename, ))
    p.start()
    p.join()
    lock.release()
    assert p.exitcode == 0
예제 #11
0
파일: test_lock.py 프로젝트: nengo/nengo
def test_can_acquire_filelock_at_most_once(tmpdir):
    filename = os.path.join(str(tmpdir), 'lock')
    lock = FileLock(filename, timeout=0.01, poll=0.01)
    lock.acquire()
    p = multiprocessing.Process(target=acquire_lock, args=(filename,))
    p.start()
    p.join()
    lock.release()
    assert p.exitcode == 0
예제 #12
0
def test_process_termination_releases_lock(tmpdir):
    filename = os.path.join(str(tmpdir), "lock")
    p = multiprocessing.Process(target=acquire_lock_and_idle, args=(filename,))
    p.start()
    while p.is_alive() and not os.path.exists(filename):
        time.sleep(0.2)
    assert p.is_alive()

    lock = FileLock(filename, timeout=0.01, poll=0.01)
    with pytest.raises(TimeoutError):
        lock.acquire()
    p.terminate()
    p.join()
    lock = FileLock(filename, timeout=0.01, poll=0.01)
    lock.acquire()
    lock.release()
예제 #13
0
파일: test_lock.py 프로젝트: nengo/nengo
def test_process_termination_releases_lock(tmpdir):
    filename = os.path.join(str(tmpdir), 'lock')
    p = multiprocessing.Process(target=acquire_lock_and_idle, args=(filename,))
    p.start()
    while p.is_alive() and not os.path.exists(filename):
        time.sleep(0.2)
    assert p.is_alive()

    lock = FileLock(filename, timeout=0.01, poll=0.01)
    with pytest.raises(TimeoutError):
        lock.acquire()
    p.terminate()
    p.join()
    lock = FileLock(filename, timeout=0.01, poll=0.01)
    lock.acquire()
    lock.release()
예제 #14
0
def test_can_acquire_filelock_at_most_once(tmpdir):
    filename = os.path.join(str(tmpdir), 'lock')
    lock = FileLock(filename, timeout=0.01, poll=0.01)
    lock.acquire()
    with pytest.raises(TimeoutError):
        lock.acquire()
    lock2 = FileLock(filename, timeout=0.01, poll=0.01)
    with pytest.raises(TimeoutError):
        lock2.acquire()
    lock.release()
예제 #15
0
파일: test_lock.py 프로젝트: weizx208/nengo
def acquire_lock_and_idle(filename):
    lock = FileLock(filename, timeout=0.01, poll=0.01)
    lock.acquire()
    while True:
        time.sleep(1.)
예제 #16
0
파일: test_lock.py 프로젝트: nengo/nengo
def acquire_lock_and_idle(filename):
    lock = FileLock(filename, timeout=0.01, poll=0.01)
    lock.acquire()
    while True:
        time.sleep(1.)