MCPcopy Create free account
hub / github.com/tox-dev/filelock / _acquire

Method _acquire

src/filelock/_soft.py:35–56  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

33 """
34
35 def _acquire(self) -> None:
36 raise_on_not_writable_file(self.lock_file)
37 ensure_directory_exists(self.lock_file)
38 flags = (
39 os.O_WRONLY # open for writing only
40 | os.O_CREAT
41 | os.O_EXCL # together with above raise EEXIST if the file specified by filename exists
42 | os.O_TRUNC # truncate the file to zero byte
43 )
44 if (o_nofollow := getattr(os, "O_NOFOLLOW", None)) is not None:
45 flags |= o_nofollow
46 try:
47 file_handler = os.open(self.lock_file, flags, self._open_mode())
48 except OSError as exception:
49 if not (
50 exception.errno == EEXIST or (exception.errno == EACCES and sys.platform == "win32")
51 ): # pragma: win32 no cover
52 raise
53 self._try_break_stale_lock()
54 else:
55 self._write_lock_info(file_handler)
56 self._context.lock_file_fd = file_handler
57
58 def _try_break_stale_lock(self) -> None:
59 with suppress(OSError, ValueError):

Callers

nothing calls this directly

Calls 5

_try_break_stale_lockMethod · 0.95
_write_lock_infoMethod · 0.95
ensure_directory_existsFunction · 0.85
_open_modeMethod · 0.80

Tested by

no test coverage detected