10000 gh-87135: threading.Lock: Raise rather than hang on Python finalization by encukou · Pull Request #135991 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-87135: threading.Lock: Raise rather than hang on Python finalization #135991

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jul 1, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Add docs
  • Loading branch information
encukou committed Jun 27, 2025
commit 657c68dfd76e98a25e7dce2ec07f2d80e6a91f72
9 changes: 8 additions & 1 deletion Doc/library/exceptions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,9 @@ The following exceptions are the exceptions that are usually raised.

* Creating a new Python thread.
* :meth:`Joining <threading.Thread.join>` a running daemon thread.
* :func:`os.fork`.
* :func:`os.fork`,
* acquiring a lock such as :cls:`threading.Lock`, when it is known that
the operation would otherwise deadlock.

See also the :func:`sys.is_finalizing` function.

Expand All @@ -440,6 +442,11 @@ The following exceptions are the exceptions that are usually raised.

:meth:`threading.Thread.join` can now raise this exception.

.. versionchanged:: next

This exception may be raised when acquiring :meth:`threading.Lock`
or :meth:`threading.RLock`.

.. exception:: RecursionError

This exception is derived from :exc:`RuntimeError`. It is raised when the
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Acquiring a :cls:`threading.Lock` or :cls:`threading.RLock` at interpreter
shutdown will raise :exc:`PythonFinalizationError` if Python can determine
that it would otherwise deadlock.
0