Acquire a lock, possibly in a non-blocking fashion. Includes backwards compatibility hacks for old versions of Python, dask and dask-distributed.
(lock, blocking=True)
| 190 | |
| 191 | |
| 192 | def acquire(lock, blocking=True): |
| 193 | """Acquire a lock, possibly in a non-blocking fashion. |
| 194 | |
| 195 | Includes backwards compatibility hacks for old versions of Python, dask |
| 196 | and dask-distributed. |
| 197 | """ |
| 198 | if blocking: |
| 199 | # no arguments needed |
| 200 | return lock.acquire() |
| 201 | else: |
| 202 | # "blocking" keyword argument not supported for: |
| 203 | # - threading.Lock on Python 2. |
| 204 | # - dask.SerializableLock with dask v1.0.0 or earlier. |
| 205 | # - multiprocessing.Lock calls the argument "block" instead. |
| 206 | # - dask.distributed.Lock uses the blocking argument as the first one |
| 207 | return lock.acquire(blocking) |
| 208 | |
| 209 | |
| 210 | class CombinedLock(Lock): |