Exemple #1
0
 def run(self):
     lock = lock_file(self.path)
     while True:
         msg = self.child_conn.recv()
         if msg == 'acquire':
             lock.acquire()
             self.child_conn.send('acquired')
         elif msg == 'release':
             lock.release()
             self.child_conn.send('released')
         elif msg == 'shutdown':
             break
     self.child_conn.close()
Exemple #2
0
def test_lock_file_multiple_processes(tmpdir):
    path = str(tmpdir.join('lock'))

    lock = lock_file(path)

    locker = Locker(path=path)
    locker.start()
    locker.parent_conn.send('acquire')
    assert 'acquired' == locker.parent_conn.recv()
    locker.parent_conn.send('release')
    assert 'released' == locker.parent_conn.recv()

    lock.acquire()
    locker.parent_conn.send('acquire')
    assert not locker.parent_conn.poll(0.1)
    lock.release()
    assert 'acquired' == locker.parent_conn.recv()
    locker.parent_conn.send('release')
    assert 'released' == locker.parent_conn.recv()
    locker.shutdown()
    locker.join()
Exemple #3
0
def test_lock_file_same_object_used_for_same_path(tmpdir):
    path = str(tmpdir.join('lock'))
    lock1 = lock_file(path)
    lock2 = lock_file(path)
    assert lock1 is lock2
Exemple #4
0
def test_lock_file_single_process(tmpdir):
    path = str(tmpdir.join('lock'))
    acquired = False
    with lock_file(path):
        acquired = True
    assert acquired