MCPcopy Create free account
hub / github.com/dask/dask / CounterLock

Class CounterLock

dask/array/tests/test_array_core.py:2339–2356  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2337
2338
2339class CounterLock:
2340 def __init__(self):
2341 self.lock = Lock()
2342 self.acquire_count = 0
2343 self.release_count = 0
2344
2345 def acquire(self, blocking: bool = True, timeout: float = -1) -> bool:
2346 acquired = self.lock.acquire(blocking=blocking, timeout=timeout)
2347 if acquired:
2348 # int.__iadd__ is atomic on GIL-enabld interpreters; when the GIL is
2349 # disabled things are nuanced and hardware-dependent. Don't risk it.
2350 self.acquire_count += 1
2351 return acquired
2352
2353 def release(self) -> None:
2354 if self.lock.locked():
2355 self.release_count += 1
2356 self.lock.release()
2357
2358
2359def test_store_locks_failure_lock_released():

Calls

no outgoing calls