Acquire a file lock on given path, then wait to release it. This worker is coordinated using events to signal when the lock should be acquired and released. :param multiprocessing.Event event_in: event object to signal when to release the lock :param multiprocessing.Event event_out:
(event_in: synchronize.Event, event_out: synchronize.Event, path: str)
| 398 | |
| 399 | |
| 400 | def _handle_lock(event_in: synchronize.Event, event_out: synchronize.Event, path: str) -> None: |
| 401 | """ |
| 402 | Acquire a file lock on given path, then wait to release it. This worker is coordinated |
| 403 | using events to signal when the lock should be acquired and released. |
| 404 | :param multiprocessing.Event event_in: event object to signal when to release the lock |
| 405 | :param multiprocessing.Event event_out: event object to signal when the lock is acquired |
| 406 | :param path: the path to lock |
| 407 | """ |
| 408 | if os.path.isdir(path): |
| 409 | my_lock = lock.lock_dir(path) |
| 410 | else: |
| 411 | my_lock = lock.LockFile(path) |
| 412 | try: |
| 413 | event_out.set() |
| 414 | assert event_in.wait(timeout=20), 'Timeout while waiting to release the lock.' |
| 415 | finally: |
| 416 | my_lock.release() |
| 417 | |
| 418 | |
| 419 | def lock_and_call(callback: Callable[[], Any], path_to_lock: str) -> None: |
nothing calls this directly
no test coverage detected
searching dependent graphs…