https://github.com/python/cpython/commit/0e150c36dee1734a6a60f1ebd924e90fb3fe1458
commit: 0e150c36dee1734a6a60f1ebd924e90fb3fe1458
branch: 3.12
author: Miss Islington (bot) <[email protected]>
committer: vsajip <[email protected]>
date: 2024-06-04T13:41:02+01:00
summary:

[3.12] gh-119819: Fix regression to allow logging configuration with multipr… 
(GH-120030) (GH-120034)

(cherry picked from commit 99d945c0c006e3246ac00338e37c443c6e08fc5c)

files:
A Misc/NEWS.d/next/Library/2024-06-04-12-23-01.gh-issue-119819.WKKrYh.rst
M Lib/logging/config.py
M Lib/test/test_logging.py

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.

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]

Reply via email to