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()
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()
def lock(): locker = CacheLocker(self.lock_file) with locker.lock('foo'): proc_is_locked.set() time.sleep(.1)
def test_free_lock(self): locker = CacheLocker(self.lock_file) with locker.lock('foo'): assert True
def lock(): locker = CacheLocker(lock_file) with locker.lock("foo"): proc_is_locked.set() time.sleep(.1)
def test_free_lock(self, lock_file): locker = CacheLocker(lock_file) with locker.lock("foo"): assert True