Acquire an advisory lock on an open file handle (cross-platform). Delegates to :mod:`portalocker`: - **POSIX** — ``fcntl.flock``; the call blocks indefinitely until acquired. - **Windows** — shared locks use the Win32 ``LockFileEx`` API (``pywin32``, which portalocker pulls in au
(fh: IO, *, exclusive: bool)
| 21 | |
| 22 | |
| 23 | def flock(fh: IO, *, exclusive: bool) -> None: |
| 24 | """Acquire an advisory lock on an open file handle (cross-platform). |
| 25 | |
| 26 | Delegates to :mod:`portalocker`: |
| 27 | |
| 28 | - **POSIX** — ``fcntl.flock``; the call blocks indefinitely until acquired. |
| 29 | - **Windows** — shared locks use the Win32 ``LockFileEx`` API (``pywin32``, |
| 30 | which portalocker pulls in automatically on Windows), so concurrent |
| 31 | readers are honoured; exclusive locks use ``msvcrt.locking``, which |
| 32 | retries for ~10s and then raises rather than blocking indefinitely. |
| 33 | |
| 34 | On failure portalocker raises :class:`portalocker.LockException` — note this |
| 35 | is *not* an ``OSError`` (e.g. on filesystems without working lock support). |
| 36 | """ |
| 37 | portalocker.lock(fh, portalocker.LOCK_EX if exclusive else portalocker.LOCK_SH) |
| 38 | |
| 39 | |
| 40 | def funlock(fh: IO) -> None: |
no outgoing calls
no test coverage detected