Skip to content

gh-96727: Document restrictions on Handler.emit() with respect to loc… #96948

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 1 commit into from
Sep 20, 2022
Merged
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
16 changes: 16 additions & 0 deletions Doc/library/logging.rst
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,22 @@ subclasses. However, the :meth:`__init__` method in subclasses needs to call
is intended to be implemented by subclasses and so raises a
:exc:`NotImplementedError`.

.. warning:: This method is called after a handler-level lock is acquired, which
is released after this method returns. When you override this method, note
that you should be careful when calling anything that invokes other parts of
the logging API which might do locking, because that might result in a
deadlock. Specifically:

* Logging configuration APIs acquire the module-level lock, and then
individual handler-level locks as those handlers are configured.

* Many logging APIs lock the module-level lock. If such an API is called
from this method, it could cause a deadlock if a configuration call is
made on another thread, because that thread will try to acquire the
module-level lock *before* the handler-level lock, whereas this thread
tries to acquire the module-level lock *after* the handler-level lock
(because in this method, the handler-level lock has already been acquired).

For a list of handlers included as standard, see :mod:`logging.handlers`.

.. _formatter-objects:
Expand Down