Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions Doc/library/pathlib.rst
Original file line number Diff line number Diff line change
Expand Up @@ -982,6 +982,24 @@ Expanding and resolving paths
strict mode, and no exception is raised in non-strict mode. In previous
versions, :exc:`RuntimeError` is raised no matter the value of *strict*.

.. note::

Even with ``strict=False``, ``Path.resolve()`` internally calls
:func:`os.getcwd` to obtain the current working directory (cwd).
If the cwd has been removed (for example, by unlinking it externally),
:func:`os.getcwd` will raise :exc:`FileNotFoundError`, causing
``resolve()`` to fail.

Therefore:

- Do **not** rely solely on ``Path.exists()`` as a pre-check for
``resolve()``: ``exists()`` only reflects the existence of the
*target* path in the filesystem, and does not detect whether the cwd
has been deleted.
- In multi-threaded or multi-process environments, a successful
``exists()`` check may still race with filesystem changes that occur
before calling ``resolve()``.


.. method:: Path.readlink()

Expand Down
Loading