From e8abbdb60a13c8972c09205c6d8b9ad072e9dc7b Mon Sep 17 00:00:00 2001 From: Vinay Sajip Date: Tue, 4 Jun 2024 13:20:50 +0100 Subject: [PATCH] =?UTF-8?q?gh-119819:=20Fix=20regression=20to=20allow=20lo?= =?UTF-8?q?gging=20configuration=20with=20multipr=E2=80=A6=20(GH-120030)?= =?UTF-8?q?=20(cherry=20picked=20from=20commit=2099d945c0c006e3246ac00338e?= =?UTF-8?q?37c443c6e08fc5c)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Vinay Sajip --- Lib/logging/config.py | 4 ++- Lib/test/test_logging.py | 26 +++++++++++++++++++ ...-06-04-12-23-01.gh-issue-119819.WKKrYh.rst | 2 ++ 3 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 Misc/NEWS.d/next/Library/2024-06-04-12-23-01.gh-issue-119819.WKKrYh.rst diff --git a/Lib/logging/config.py b/Lib/logging/config.py index 3aec8361aeff6e..c98eb6c8215d1a 100644 --- a/Lib/logging/config.py +++ b/Lib/logging/config.py @@ -788,8 +788,10 @@ def configure_handler(self, config): # raise ValueError('No handlers specified for a QueueHandler') if 'queue' in config: from multiprocessing.queues import Queue as MPQueue + from multiprocessing import Manager as MM + proxy_queue = MM().Queue() qspec = config['queue'] - if not isinstance(qspec, (queue.Queue, MPQueue)): + if not isinstance(qspec, (queue.Queue, MPQueue, type(proxy_queue))): if isinstance(qspec, str): q = self.resolve(qspec) if not callable(q): diff --git a/Lib/test/test_logging.py b/Lib/test/test_logging.py index fa455035e5c41d..d2a392bed1c8a7 100644 --- a/Lib/test/test_logging.py +++ b/Lib/test/test_logging.py @@ -3894,6 +3894,32 @@ def test_config_queue_handler(self): msg = str(ctx.exception) self.assertEqual(msg, "Unable to configure handler 'ah'") + @unittest.skipIf(support.is_wasi, "WASI does not have multiprocessing.") + def test_multiprocessing_queues(self): + # See gh-119819 + cd = copy.deepcopy(self.config_queue_handler) + from multiprocessing import Queue as MQ, Manager as MM + q1 = MQ() # this can't be pickled + q2 = MM().Queue() # a proxy queue for use when pickling is needed + for qspec in (q1, q2): + fn = make_temp_file('.log', 'test_logging-cmpqh-') + cd['handlers']['h1']['filename'] = fn + cd['handlers']['ah']['queue'] = qspec + qh = None + try: + self.apply_config(cd) + qh = logging.getHandlerByName('ah') + self.assertEqual(sorted(logging.getHandlerNames()), ['ah', 'h1']) + self.assertIsNotNone(qh.listener) + self.assertIs(qh.queue, qspec) + self.assertIs(qh.listener.queue, qspec) + finally: + h = logging.getHandlerByName('h1') + if h: + self.addCleanup(closeFileHandler, h, fn) + else: + self.addCleanup(os.remove, fn) + def test_90195(self): # See gh-90195 config = { diff --git a/Misc/NEWS.d/next/Library/2024-06-04-12-23-01.gh-issue-119819.WKKrYh.rst b/Misc/NEWS.d/next/Library/2024-06-04-12-23-01.gh-issue-119819.WKKrYh.rst new file mode 100644 index 00000000000000..f9e49c00f671f2 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2024-06-04-12-23-01.gh-issue-119819.WKKrYh.rst @@ -0,0 +1,2 @@ +Fix regression to allow logging configuration with multiprocessing queue +types. pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy