From 4334f56744cae914fc8d84ee09f9d5e4b38fbfb3 Mon Sep 17 00:00:00 2001 From: Duane Griffin Date: Thu, 26 Jun 2025 10:00:57 +1200 Subject: [PATCH 1/3] gh-91555: add warning to docs about possibility of deadlock/infinite recursion Attempt to clarify in the documentation that care must be taken when using multiprocessing classes to implement logging since they have builtin internal logging, and hence may cause deadlock/infinite recursion. --- Doc/library/logging.handlers.rst | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Doc/library/logging.handlers.rst b/Doc/library/logging.handlers.rst index 8f3aa1dfdd0cde..be397df2e228e4 100644 --- a/Doc/library/logging.handlers.rst +++ b/Doc/library/logging.handlers.rst @@ -1059,6 +1059,14 @@ possible, while any potentially slow operations (such as sending an email via .. note:: If you are using :mod:`multiprocessing`, you should avoid using :class:`~queue.SimpleQueue` and instead use :class:`multiprocessing.Queue`. + .. warning:: + + The :mod:`multiprocessing` module uses an internal logger created and + accessed via :meth:`~multiprocessing.get_logger`. + :class:`multiprocessing.Queue` will log ``DEBUG`` level messages upon + items being queued. If those log messages are processed by the same + :class:`QueueHandler` it will cause a deadlock or infinite recursion. + .. method:: emit(record) Enqueues the result of preparing the LogRecord. Should an exception From 866be7972dd9549d548a8804d3084bfa88cb3355 Mon Sep 17 00:00:00 2001 From: Duane Griffin Date: Thu, 26 Jun 2025 21:23:55 +1200 Subject: [PATCH 2/3] Update Doc/library/logging.handlers.rst Co-authored-by: Vinay Sajip --- Doc/library/logging.handlers.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Doc/library/logging.handlers.rst b/Doc/library/logging.handlers.rst index be397df2e228e4..259eccc9590a54 100644 --- a/Doc/library/logging.handlers.rst +++ b/Doc/library/logging.handlers.rst @@ -1064,8 +1064,8 @@ possible, while any potentially slow operations (such as sending an email via The :mod:`multiprocessing` module uses an internal logger created and accessed via :meth:`~multiprocessing.get_logger`. :class:`multiprocessing.Queue` will log ``DEBUG`` level messages upon - items being queued. If those log messages are processed by the same - :class:`QueueHandler` it will cause a deadlock or infinite recursion. + items being queued. If those log messages are processed by a + :class:`QueueHandler` using the same :class:`multiprocessing.Queue` instance, it will cause a deadlock or infinite recursion. .. method:: emit(record) From 46a26b14fd48566599af61f40b72937e8473155a Mon Sep 17 00:00:00 2001 From: Vinay Sajip Date: Thu, 26 Jun 2025 10:53:37 +0100 Subject: [PATCH 3/3] Change whitespace. --- Doc/library/logging.handlers.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Doc/library/logging.handlers.rst b/Doc/library/logging.handlers.rst index 259eccc9590a54..d74ef73ee28497 100644 --- a/Doc/library/logging.handlers.rst +++ b/Doc/library/logging.handlers.rst @@ -1065,7 +1065,8 @@ possible, while any potentially slow operations (such as sending an email via accessed via :meth:`~multiprocessing.get_logger`. :class:`multiprocessing.Queue` will log ``DEBUG`` level messages upon items being queued. If those log messages are processed by a - :class:`QueueHandler` using the same :class:`multiprocessing.Queue` instance, it will cause a deadlock or infinite recursion. + :class:`QueueHandler` using the same :class:`multiprocessing.Queue` instance, + it will cause a deadlock or infinite recursion. .. method:: emit(record)