Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7a8ac38

Browse files
authored
[3.10] gh-96727: Document restrictions on Handler.emit() with respect to locking. (GH-96948) (GH-96951)
(cherry picked from commit 6ad47b4)
1 parent dcff50a commit 7a8ac38

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

Doc/library/logging.rst

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,22 @@ subclasses. However, the :meth:`__init__` method in subclasses needs to call
522522
is intended to be implemented by subclasses and so raises a
523523
:exc:`NotImplementedError`.
524524

525+
.. warning:: This method is called after a handler-level lock is acquired, which
526+
is released after this method returns. When you override this method, note
527+
that you should be careful when calling anything that invokes other parts of
528+
the logging API which might do locking, because that might result in a
529+
deadlock. Specifically:
530+
531+
* Logging configuration APIs acquire the module-level lock, and then
532+
individual handler-level locks as those handlers are configured.
533+
534+
* Many logging APIs lock the module-level lock. If such an API is called
535+
from this method, it could cause a deadlock if a configuration call is
536+
made on another thread, because that thread will try to acquire the
537+
module-level lock *before* the handler-level lock, whereas this thread
538+
tries to acquire the module-level lock *after* the handler-level lock
539+
(because in this method, the handler-level lock has already been acquired).
540+
525541
For a list of handlers included as standard, see :mod:`logging.handlers`.
526542

527543
.. _formatter-objects:

0 commit comments

Comments
 (0)