MCPcopy Index your code
hub / github.com/bpython/bpython / UnixFileLock

Class UnixFileLock

bpython/filelock.py:62–80  ·  view source on GitHub ↗

Simple file locking for Unix using fcntl

Source from the content-addressed store, hash-verified

60 import errno
61
62 class UnixFileLock(BaseLock):
63 """Simple file locking for Unix using fcntl"""
64
65 def __init__(self, fileobj, mode: int = 0) -> None:
66 super().__init__()
67 self.fileobj = fileobj
68 self.mode = mode | fcntl.LOCK_EX
69
70 def acquire(self) -> None:
71 try:
72 fcntl.flock(self.fileobj, self.mode)
73 self.locked = True
74 except OSError as e:
75 if e.errno != errno.ENOLCK:
76 raise e
77
78 def release(self) -> None:
79 self.locked = False
80 fcntl.flock(self.fileobj, fcntl.LOCK_UN)
81
82 has_fcntl = True
83except ImportError:

Callers 1

FileLockFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected