MCPcopy Index your code
hub / github.com/vastsa/FileCodeBox / _lock_file

Function _lock_file

core/database.py:42–54  ·  view source on GitHub ↗
(file_obj: IO[str])

Source from the content-addressed store, hash-verified

40
41
42def _lock_file(file_obj: IO[str]) -> None:
43 if os.name == "nt":
44 import msvcrt
45
46 # Windows 需要锁定至少 1 字节
47 if os.fstat(file_obj.fileno()).st_size == 0:
48 file_obj.write("0")
49 file_obj.flush()
50 msvcrt.locking(file_obj.fileno(), msvcrt.LK_LOCK, 1)
51 else:
52 import fcntl
53
54 fcntl.flock(file_obj.fileno(), fcntl.LOCK_EX)
55
56
57def _unlock_file(file_obj: IO[str]) -> None:

Callers

nothing calls this directly

Calls 1

writeMethod · 0.80

Tested by

no test coverage detected