Пример #1
0
    def test_locked_by_process_no_block(self):
        proc_is_locked = multiprocessing.Event()

        def lock():
            locker = CacheLocker(self.lock_file)
            with locker.lock('foo'):
                proc_is_locked.set()
                time.sleep(10)

        p = multiprocessing.Process(target=lock)
        p.start()
        # wait for process to start
        proc_is_locked.wait()

        locker = CacheLocker(self.lock_file)

        # test unlocked bar
        with locker.lock('bar', no_block=True):
            assert True

        # test locked foo
        try:
            with locker.lock('foo', no_block=True):
                assert False
        except CacheLockedError:
            pass
        finally:
            p.terminate()
            p.join()
Пример #2
0
 def test_locked_by_process_no_block(self):
     proc_is_locked = multiprocessing.Event()
     def lock():
         locker = CacheLocker(self.lock_file)
         with locker.lock('foo'):
             proc_is_locked.set()
             time.sleep(10)
     
     p = multiprocessing.Process(target=lock)
     p.start()
     # wait for process to start
     proc_is_locked.wait()
     
     locker = CacheLocker(self.lock_file)
     
     # test unlocked bar
     with locker.lock('bar', no_block=True):
         assert True
     
     # test locked foo
     try:
         with locker.lock('foo', no_block=True):
             assert False
     except CacheLockedError:
         pass
     finally:
         p.terminate()
         p.join()
Пример #3
0
 def test_locked_by_process_waiting(self):
     proc_is_locked = multiprocessing.Event()
     def lock():
         locker = CacheLocker(self.lock_file)
         with locker.lock('foo'):
             proc_is_locked.set()
             time.sleep(.1)
     
     p = multiprocessing.Process(target=lock)
     start_time = time.time()
     p.start()
     # wait for process to start
     proc_is_locked.wait()
     
     locker = CacheLocker(self.lock_file, polltime=0.02)
     try:
         with locker.lock('foo', no_block=False):
             diff = time.time() - start_time
             assert diff > 0.1
     finally:
         p.terminate()
         p.join()
Пример #4
0
    def test_locked_by_process_waiting(self):
        proc_is_locked = multiprocessing.Event()

        def lock():
            locker = CacheLocker(self.lock_file)
            with locker.lock('foo'):
                proc_is_locked.set()
                time.sleep(.1)

        p = multiprocessing.Process(target=lock)
        start_time = time.time()
        p.start()
        # wait for process to start
        proc_is_locked.wait()

        locker = CacheLocker(self.lock_file, polltime=0.02)
        try:
            with locker.lock('foo', no_block=False):
                diff = time.time() - start_time
                assert diff > 0.1
        finally:
            p.terminate()
            p.join()
Пример #5
0
 def lock():
     locker = CacheLocker(self.lock_file)
     with locker.lock('foo'):
         proc_is_locked.set()
         time.sleep(.1)
Пример #6
0
 def test_free_lock(self):
     locker = CacheLocker(self.lock_file)
     with locker.lock('foo'):
         assert True
Пример #7
0
 def lock():
     locker = CacheLocker(self.lock_file)
     with locker.lock('foo'):
         proc_is_locked.set()
         time.sleep(.1)
Пример #8
0
 def test_free_lock(self):
     locker = CacheLocker(self.lock_file)
     with locker.lock('foo'):
         assert True
Пример #9
0
 def lock():
     locker = CacheLocker(lock_file)
     with locker.lock("foo"):
         proc_is_locked.set()
         time.sleep(.1)
Пример #10
0
 def test_free_lock(self, lock_file):
     locker = CacheLocker(lock_file)
     with locker.lock("foo"):
         assert True