def test_lock_file_non_blocking(self): with TempDir() as d: path = os.path.join(d, 'tempfile') fd = lock_file(path, timeout=0) self.assertTrue(fd) self.assertFalse(self.try_access_from_other_process(path)) os.close(fd)
def try_file_lock(path): fd = lock_file(path, timeout=2) sys.exit(0 if fd else 1)