summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2024-06-04 12:46:41 (GMT)
committerGitHub <noreply@github.com>2024-06-04 12:46:41 (GMT)
commit720a44d414b68943c766716145d7c6d15ea213de (patch)
treef738e10b14a110a38305a338fdbfb8e8249fa368
parentfeaecf8c33444d44a5a554680f270c5c614185d3 (diff)
downloadcpython-720a44d414b68943c766716145d7c6d15ea213de.zip
cpython-720a44d414b68943c766716145d7c6d15ea213de.tar.gz
cpython-720a44d414b68943c766716145d7c6d15ea213de.tar.bz2
[3.13] gh-119819: Fix regression to allow logging configuration with multipr… (GH-120030) (GH-120035)
(cherry picked from commit 99d945c0c006e3246ac00338e37c443c6e08fc5c)
-rw-r--r--Lib/logging/config.py4
-rw-r--r--Lib/test/test_logging.py26
-rw-r--r--Misc/NEWS.d/next/Library/2024-06-04-12-23-01.gh-issue-119819.WKKrYh.rst2
3 files changed, 31 insertions, 1 deletions
diff --git a/Lib/logging/config.py b/Lib/logging/config.py
index ac45d68..0b10bf8 100644
--- a/Lib/logging/config.py
+++ b/Lib/logging/config.py
@@ -781,8 +781,10 @@ class DictConfigurator(BaseConfigurator):
# 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 9ebd345..d3e5ac2 100644
--- a/Lib/test/test_logging.py
+++ b/Lib/test/test_logging.py
@@ -3926,6 +3926,32 @@ class ConfigDictTest(BaseTest):
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 0000000..f9e49c0
--- /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.