MCPcopy Create free account
hub / github.com/VectifyAI/OpenKB / flock

Function flock

openkb/locks.py:23–37  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

21
22
23def 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
40def funlock(fh: IO) -> None:

Callers 2

_with_global_config_lockFunction · 0.90
kb_lockFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected