MCPcopy Create free account
hub / github.com/tox-dev/filelock / test_threaded_shared_lock_obj

Function test_threaded_shared_lock_obj

tests/test_filelock.py:242–259  ·  view source on GitHub ↗
(lock_type: type[BaseFileLock], tmp_path: Path)

Source from the content-addressed store, hash-verified

240
241@pytest.mark.parametrize("lock_type", [FileLock, SoftFileLock])
242def test_threaded_shared_lock_obj(lock_type: type[BaseFileLock], tmp_path: Path) -> None:
243 # Runs 100 threads, which need the filelock. The lock must be acquired if at least one thread required it and
244 # released, as soon as all threads stopped.
245 lock_path = tmp_path / "a"
246 lock = lock_type(str(lock_path))
247
248 def thread_work() -> None:
249 for _ in range(100):
250 with lock:
251 assert lock.is_locked
252
253 threads = [ExThread(target=thread_work, name=f"t{i}") for i in range(100)]
254 for thread in threads:
255 thread.start()
256 for thread in threads:
257 thread.join()
258
259 assert not lock.is_locked
260
261
262@pytest.mark.parametrize("lock_type", [FileLock, SoftFileLock])

Callers

nothing calls this directly

Calls 2

ExThreadClass · 0.85
joinMethod · 0.80

Tested by

no test coverage detected